问题描述
这是我的代码
weight = float(input("Please Enter Your Weight In KIlograms: "))
height = float(input("Please Enter Your Height In Meters: "))
result = weight / height ** height
print("Your BMI is " + result)
这是错误
OverflowError:(34,“结果太大”)
我真的还不熟悉技术术语,因此您可能需要在解释中更加具体。
解决方法
尝试这样的事情
height = float(input("Input your height in meters: "))
weight = float(input("Input your weight in kilogram: "))
print("Your body mass index is: ",round(weight / (height * height),2))
,
您的代码需要进行一些更改。您的最终打印语句尝试将一个字符串和一个浮点数连接起来,即字符串“ Your BMI is”是浮点数。因此,您必须使它们与下面的类型相同。 ("Your BMI is " + str(result))
。而且,BMI方程是Weight / Height ^ 2而不是Weight / Height ^ Height。因此,将计算部分更改为result = weight / height ** 2
。
weight = float(input("Please Enter Your Weight In Kilograms: "))
height = float(input("Please Enter Your Height In Meters: "))
result = weight / height ** 2
print("Your BMI is " + str(result))