【发布时间】:2017-11-03 10:13:52
【问题描述】:
我正在尝试学习 python,作为测试我尝试制作一个 BMI 计算器
#BMI Calculator
name = raw_input ("What is your name?: ")
weight = raw_input ("Hello %s What is your weight? (kilo): "% (name))
height = raw_input ("And what is your height? (cm) ")
#Calculations: weight / height^2 * 10000
weight = int(weight)
height = int(height)
BMI = (weight / height ** 2) * 10000
print "%s, your BMI is %s"% (name, BMI)
但是计算似乎有问题,因为我的 BMI 总是为 0?怎么了?
【问题讨论】:
-
您使用的是 Python 2,我猜?除非您病态肥胖,否则
height将大于weight,因此根据 dup,答案将为零。 -
改变这一行 BMI = (体重/身高 ** 2) * float(10000)
-
更好的 BMI = (体重/浮动(身高) ** 2) * 10000
标签: python