Python 我的体重指数计算器正在倒转
我为学校编写的Bmi计算器正在反向生成输出,它首先调用用户信息,而不是名称信息。请帮帮我,我需要换个方向Python 我的体重指数计算器正在倒转,python,python-3.x,Python,Python 3.x,我为学校编写的Bmi计算器正在反向生成输出,它首先调用用户信息,而不是名称信息。请帮帮我,我需要换个方向 user = str end = False def bmi_intro(): print("BMI Calculator") while end == False: user = input("Enter students name or '0' to quit: ") if user == "0": print
user = str
end = False
def bmi_intro():
print("BMI Calculator")
while end == False:
user = input("Enter students name or '0' to quit: ")
if user == "0":
print("end of report!")
else:
def userName(str):
user = str
print("Lets gather your information,", user)
break
get_height = float(input("Please enter your height in inches: "))
get_weight = float(input("Please enter your weight: "))
body_mass_index = (get_weight * 703) / (get_height ** 2)
print ("Your bmi is: ", body_mass_index)
def main():
get_height = 0.0
get_weight = 0.0
body_mass_index = 0.0
bmi_intro()
更正缩进和删除
break
语句可以解决您的问题(我已尝试尽可能少地编辑您的代码,我认为这将有助于您理解代码):
您的代码中存在许多问题:
- 您尚未设置
end
- 您没有正确缩进
- 在这种情况下,
功能是冗余的main
def bmi_intro():
end = False
print("BMI Calculator")
while end == False:
user = input("Enter student's name or '0' to quit: ")
if user == "0":
print("end of report!")
end = True
else:
print("Lets gather your information,", user)
get_height = float(input("Please enter your height in inches: "))
get_weight = float(input("Please enter your weight: "))
body_mass_index = (get_weight * 703) / (get_height ** 2)
print ("Your bmi is:", body_mass_index)
bmi_intro()
其他建议
您可能希望在问题中指出重量的计量单位,即:
get_weight = float(input("Please enter your weight in pounds (lbs): "))
除非您计划扩展此代码和/或添加其他函数,否则不需要函数。如果愿意,您可以取消函数定义和函数调用。请修复缩进。您需要删除
中断
,并缩进与用户体重和身高相关的行,使其位于内,否则
。您还需要设置end
的值。Python不是一种静态类型的语言,这意味着在赋值之前不需要定义变量的类型。因此,在您的情况下,user=str
什么都不做。
get_weight = float(input("Please enter your weight in pounds (lbs): "))