(一)并列式
# 输入部分
score = float(input('成绩:'))
# 处理部分
level = ''
if score > 100:
level = '超出范围'
if score >= 90 and score <= 100:
level = '优秀'
if score >= 80 and score < 90:
level = '良好'
if score >= 70 and score < 80:
level = '中等'
if score >= 60 and score < 70:
level = '及格'
if score >= 0 and score < 60:
level = '不及格'
if score < 0:
level = '超出范围'
# 输出部分
print('等级:{}'.format(level))
(二)嵌套式
# 输入部分
score = float(input('成绩:'))
# 处理部分
level = ''
if score > 100:
level = '超出范围'
else:
if score >= 90:
level = '优秀'
else:
if score >= 80:
level = '良好'
else:
if score >= 70:
level = '中等'
else:
if score >= 60:
level = '及格'
else:
if score >= 0:
level = '不及格'
else:
level = '超出范围'
# 输出部分
print('等级:{}'.format(level))
(三)拓展式
# 输入部分
score = float(input('成绩:'))
# 处理部分
level = ''
if score > 100:
level = '超出范围'
elif score >= 90:
level = '优秀'
elif score >= 80:
level = '良好'
elif score >= 70:
level = '中等'
elif score >= 60:
level = '及格'
elif score >= 0:
level = '不及格'
else:
level = '超出范围'
# 输出部分
print('等级:{}'.format(level))