自学python笔记 2 --条件判断

'''
#if:   elif:   elif:  else
#例子:输入用户年龄,根据年龄打印不同的内容,在 Python程序中
#因为低版本python用input时输入的内容全是str型,高点版本输入什么就是什么类型,
#字符串str转换成int: int_value = int(str_value)
#int转换成字符串str: str_value = str(int_value)

age = input('输入用户年龄:\n')
print('age类型为',type(age))
age1 = int(age)
print('age1类型为',type(age1))

print('you age is %d.' % age1)
if age1 >= 18:
    print('you are adult!')
elif age1 >= 6:
    print('you are teenager!')
else:
    print('you are kid!')
    
'''

#练习:小明身高咼1.75,体重80.5kg。请根据BMI公式(体重除以身高的平方)帮小明计算他的BMI指数,并根据BMI指数
height = 1.75
weight = 80.5
BMI = weight / (height * height)

if BMI < 18.5:
    print('过轻')
elif BMI < 25:
    print('正常')
elif BMI < 28:
    print('过重')
elif BMI < 32:
    print('肥胖')
else:
    print('严重肥胖')


 

猜你喜欢

转载自blog.csdn.net/yuer1304587444/article/details/81181483