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()
编辑
您应该调用函数,请查看
Calculate
的更正代码因为没有在函数名后面加括号,所以它使用函数对象本身的值,而不是调用函数的结果。你知道吗
函数名后加括号:
另外,您的
GetWeight
和GetHeight
函数没有返回任何值;您需要解决这个问题。你知道吗为了调用函数,请使用
()
,如下所示:现在,您正在尝试将函数与整数相乘。你知道吗
Read more about functions in Python.
相关问题 更多 >
编程相关推荐