#选择结构的嵌套 #输入学生成绩,并确定他们的成绩等级#嵌套语句 score=int(input("请输入一个1~100的数:")) num=0 degree=['E','D','C','B','A'] if score<0 or score>100:print("请重新输入") else:num=score//10if num<5:num=5 print('您的分数为{0},等级评价为{1}'.format(score,degree[num-5]))
#多分枝选择结构
score=int(input("请输入你的成绩: "))
if score>100 or score<0:
grade='重新输入'
elif score>=0 and score<60:
grade="差"
elif score>=60 and score<70:
grade="中等"
elif score>=70 and score<90:
grade="普通"
#elif score>=90 and score<=100:
#grade="优秀"
#补充一点,elif下面还可以加一个else,代表意义是除却上述条件语句的范围,代表的范围
else:
grade="优秀"
#可以看到将原本最后两行的elif注释掉,变成else同样可以运行成功
print('您的分数为{0},等级评价为{1}'.format(score,grade))
本文发布于:2024-02-02 19:39:05,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170687394345995.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |