当前获取一个TypeError,该错误声明:不支持*:“function”和“float”的操作数类型

2024-09-28 17:20:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我现在是一个学习python编程的一年级学生,我们目前正在研究模块/函数。我的代码出现错误:

Traceback (most recent call last):   File "C:/Users/User/Desktop/CISC 300 - Dolce/Turn In/A3 Darryl Lardizabal pg121 #4 rework.py", line 86, in <module>
    main()   File "C:/Users/User/Desktop/CISC 300 - Dolce/Turn In/A3 Darryl Lardizabal pg121 #4 rework.py", line 81, in main
    yearly = totalYearly (totalMonthly)   File "C:/Users/User/Desktop/CISC 300 - Dolce/Turn In/A3 Darryl Lardizabal pg121 #4 rework.py", line 50, in totalYearly
    totalYearly = totalMonthly*ONE_YEAR TypeError: unsupported operand type(s) for *: 'function' and 'float'

我尝试过用多种方式来处理这行代码,包括totatYearly=totalMonthly*12等等,但是不确定它是否就在那里,或者代码有什么问题。在

^{pr2}$

谢谢你的帮助!在

^{3}$

Tags: 代码inpyusersa3turnfiledesktop
1条回答
网友
1楼 · 发布于 2024-09-28 17:20:34

当计算年度值并显示结果时,传递的是函数而不是它们的结果作为参数。解决这个问题,它就会起作用:

##Calculate Monthly Costs of User
monthly = totalMonthly (loanPayment, insurance, gas, oil, tires, maintenance)

##Calculate Annual Costs of User
#yearly = totalYearly (totalMonthly)
yearly = totalYearly (monthly)

##Show Costs to User for both per month and per year
#showCosts (totalMonthly, totalYearly)
showCosts (monthly, yearly)

更新下面是一个简短的示例,说明现在发生了什么,以及上面的解决方法:

^{pr2}$

相关问题 更多 >