Python style百分制转五分制

百分制转五分制,就是把考试分数用ABCDE表示出来

A90~100
B80~89
C70~79
D60~69
E60以下

输入为一个整数,当这个整数不在0~100 的范围内的时候,输出“data error”.


正常的风格是

score=int(input())
if (score > 100 or score < 0):
    print('Data error!')
else:
    if score<=100 and score>=90:
        print("A")
    if score<90 and score>=80:
        print("B")
    if score<80 and score>=70:
        print("C")
    if score<70 and score>=60:
        print("D")
    if score<60:
        print("E")

也可以将五分制构造出一个字符串'EEEEEEDCBAA',用以下方法实现这个功能:

score = int(input())
degree = 'EEEEEEDCBAA'
if (score > 100 or score < 0):
    print('Data error!')
else:
    print(degree[score//10])

这样的方法更加Pythonic

  • 2
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值