python选择结构中的多分支结构示例

前言:每日打卡

要求:从键盘录入一个整数成绩,90~100为A,80~89为B,70~79为C,60~69为D,0~59为E

小于0或大于100的为非法数据。

score = int(input("请输入你的成绩:")

if score >= 90 and score <= 100:

print('A级')

elif score >= 80 and score <= 89:

print('B级')

elif score >= 70 and score <= 79:

print('C级')

elif score >= 60 and score <= 69:

print('D级')

elif score >= 0 and score <= 59:

print('E级')

else:

print('对不起,成绩输入有误,不在其有效范围内')

上述代码中条件表达式也可以写成:

score = int(input("请输入你的成绩:"))
if 90 <= score <=100:
print(‘A级’)
elif 80 <= score <= 89:
print('B级')
elif 70 <= score <= 79:
print('C级')
elif 60 <= score <= 69:
print('D级')
elif 0 <= score <= 59:
print('E级')
else:
print("对不起,成绩输入有误,输入值不在其有效范围内")

注:上述条件表达式仅在python中可以实现,在其他编程语言中不能

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值