标签:第四周 表达式 条件判断 inpu 异常类 保留字 python 标准 与或非
#示例
try:
num = eval(input(”请输入一个整数:“))
print(num**2)
except:#可标注异常类型,仅相应该类型如except NameError
print("输入不是整数")
分支例题(BMI)
#BMI,写字板打开变乱码,懒得改了,大概是偏廋,正常,偏胖,肥胖,分国际标准和国内标准
height,weight = eval(input())
bmi = weight / pow(height,2)
print(bmi)
who,nat = "",""
if bmi< 18.5:
who,nat = "鍋忓粙","鍋忓粙"
elif 18.5 <=bmi < 24:
who,nat = "姝e父","姝e父"
elif 24 <=bmi <25:
who,nat = "鍋忚儢","鍋忚儢"
elif 25 <=bmi <28:
who,nat ="鍋忚儢","鍋忚儢"
elif 24 <=bmi <25:
who,nat ="鍋忚儢","鑲ヨ儢"
else:
who,nat = "鑲ヨ儢","鑲ヨ儢"
print("BMI鎸囨爣涓猴細鍥介檯{0},鍥藉唴{1}".format(who,nat))
python第四周程序控制结构之分支,条件判断,程序异常处理
标签:第四周 表达式 条件判断 inpu 异常类 保留字 python 标准 与或非
原文地址:https://www.cnblogs.com/mouzaisi/p/12177840.html