python - TypeError: unsupported operand type(s) for *: 'function' and 'int' in Python, 无法计算解决方案
问题描述
我尝试从其他示例中理解此错误,但我无法弄清楚。代码在标题中返回错误。
def truckloads_of_asphalt(miles, lanes, asphalt_depth):
total_feet = ((miles*5280) * (lanes * 12)) * (asphalt_depth/12)
total_asphalt_truck = math.ceil((((total_feet * 145)/2000))/5)
return total_asphalt_truck
asphalt_cost = (truckloads_of_asphalt * 5 * 145)
print('Cost of asphalt : ', (asphalt_cost))
问题基本上是我试图打印沥青成本的值,这是结果:(truckloads_of_asphalt * 5 * 145)
但我收到了这个错误。
解决方案
除了你没事之外,你 从来没有打电话给你function
并将返回值分配给它variable
import math
def truckloads_of_asphalt(miles, lanes, asphalt_depth):
total_feet = ((miles*5280) * (lanes * 12)) * (asphalt_depth/12)
total_asphalt_truck = math.ceil((((total_feet * 145)/2000))/5)
return total_asphalt_truck
vash = truckloads_of_asphalt(60, 2, 4)
asphalt_cost = (vash * 5 * 145)
print('Cost of asphalt : ', (asphalt_cost))
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 trucks.py Cost of asphalt : 26643025
值得熟悉f-strings
:
print(f"Cost of asphalt: {asphalt_cost}")
推荐阅读
- c# - 在 C#/VB.Net 中动态传递函数作为参数
- java - 如何将元素移动到java中排序数组的底部?
- html - Google Apps脚本如何将事件侦听器添加到一组具有相同名称的复选框中的每个复选框
- c++ - 具有交错类型和非类型参数的参数包的模板
- vue.js - vuex 模块 appState 不适用于作为第一个参数传递的模块命名空间
- c# - 如何在asp.net MVC 5中以引导模式显示各种内容?
- assembly - 在 68k 中实现 while 循环
- php - 打开购物车 | 为所有客户组设置默认税率,包括将来可能添加的客户组 | PHP
- c - 需要帮助找到解决问题的逻辑解决方案
- python - 利用 Tkinter 的 Grid Manager 将按钮居中并填充整个框架