eilf&if嵌套
2018-05-20 本文已影响0人
python小可爱
elif功能:

案例:
score = 77
if score>=90 and score<=100:
print('本次考试,等级为A')
elif score>=80 and score<90:
print('本次考试,等级为B')
elif score>=70 and score<80:
print('本次考试,等级为C')
elif score>=60 and score<70:
print('本次考试,等级为D')
elif score>=0 and score<60:
print('本次考试,等级为E')
注意:

if 嵌套:

案例:
chePiao = 1 # 用1代表有车票,0代表没有车票
daoLenght = 9 # 刀子的长度,单位为cm
if chePiao == 1:
print("有车票,可以进站")
if daoLenght < 10:
print("通过安检")
print("终于可以见到Ta了,美滋滋~~~")
else:
print("没有通过安检")
print("刀子的长度超过规定,等待警察处理...")
else:
print("没有车票,不能进站")
print("亲爱的,那就下次见了")
结果:
