字符串定义出错
""bmr 基础代谢率计算
"""
def main():
y_or_n = input('是否退出程序:')
while y_or_n == 'n':
# 性别
gender = input('请输入您的性别:')
# 体重 (kg)
weight = float(input('体重:'))
# 身高 (cm)
hight = float(input('身高:'))
# 年龄
age = int(input ('年龄:'))
if gender == "男":
bmr = 13.7*weight + 5.0*hight - 6.8*age + 66
elif gender =="女":
bmr = 9.6*weight + 1.8*hight - 4.7*age + 656
else :
bmr = -1
if bmr != -1:
print("基础代谢率 :",bmr)
else :
print("暂不支持该性别")
"""gender = "男"
weight = 70
height = 175
age = 24
if gender == "男":
bmr = 13.7*weight + 5.0*height - 6.8*age + 66
elif gender =="女":
bmr = 9.6*weight + 1.8*height - 4.7*age + 656
else :
bmr = -1
"""
y_or_n == intput("是否退出程序(y/n)?:")
if __name__ =="__main__":
main()
报错 代码 : while y_or_n == 'n':
NameError: name 'y_or_n' is not defined