【发布时间】:2016-02-17 21:01:51
【问题描述】:
def GetWeight():
GetWeight = 0.0
Weight = float(input("How much do you weigh in pounds?\n "))
def GetHeight():
Heightinches = 0.0
Heightinches = input("Enter your height in inches: ")
def Calculate():
BMI = eval (GetWeight * 703 / (GetHeight * GetHeight))
print ("Your BMI is", BMI)
main()
程序一直运行到出现错误的计算模块:
TypeError: unsupported operand type(s) for *: 'function' and 'int'
根据您的建议,代码现在如下所示:
def GetWeight():
GetWeight = 0.0
Weight = float(input("How much do you weigh in pounds?\n "))
def GetHeight():
Heightinches = 0.0
Heightinches = input("Enter your height in inches:\n ")
def Calculate():
BMI = eval (GetWeight() * 703 / (GetHeight() * GetHeight()))
print("Your BMI is", BMI)
main()
我已经修改了代码,但是现在程序卡在一个连续的问答循环中,并且计算模块永远不会启动。
def GetWeight():
GetWeight = 0.0
Weight = float(input("How much do you weigh in pounds?\n "))
return GetWeight
def GetHeight():
Heightinches = 0.0
Heightinches = input("Enter your height in inches:\n ")
return GetHeight
def Calculate():
BMI = eval (GetWeight() * 703 / (GetHeight() * GetHeight()))
print("Your BMI is", BMI)
main()
【问题讨论】:
-
除了功能的问题,你认为你需要
eval吗? -
我以为eval是用来让python计算方程的。我错了吗?
标签: python error-handling typeerror