程序:
import turtle
def main():
y_or_n = input('是否退出程序(y/n)?')
while y_or_n!='y':
# gender=input('性别:')
# weight=float(input('体重(kg):'))
# height=float(input('身高(cm):'))
# age=float(input('年龄:'))
print('请输入以下信息,用空格分隔')
str=input('性别 体重(kg) 身高(cm) 年龄:')
list=str.split(' ')
gender=list[0]
weight=float(list[1])
height=float(list[2])
age=float(list[3])
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)+655
else:
bmr=-1
if bmr!=-1:
print('性别:{},体重:{}公斤,身高:{}厘米,年龄:{}岁'.format(gender, weight, height, age))
print('基础代谢率:{}大卡'.format(bmr))
else:
print('性别请输入男或女')
print('******************************')
y_or_n = input('是否退出程序(y/n)?')
if __name__=='__main__':
main()
运行结果: