首页 Python基础入门视频教程 Python if多条件嵌套判断语句用法
pay pay

Python if多条件嵌套判断语句用法

日期: 二月 14, 2023, 7:18 a.m.
阅读: 442
作者: Python自学网-村长

摘要: 判断-分支嵌套判断

'''
1.首先判断输入的分数是不是在0-100之间

2.然后把好学生和差学生分开

差生:0分、很差(1-29)、较差(30-49)、不及格(50-59)
好生:及格(60-69)、良好(70-79)、优秀(80-99)、100分
'''
score = input('你的分数是:')
if 0 <= int(score) <= 100:
    if int(score) >= 60:
        if 69 >= int(score) >= 60:
            print('你的分数是%d,及格' % int(score))
        if 79 >= int(score) >= 70:
            print('你的分数是%d,良好' % int(score))
        if 99 >= int(score) >= 80:
            print('你的分数是%d,优秀' % int(score))
        if int(score) == 100:
            print('你的分数是{}'.format(score))
    else:
        if 50 <= int(score) <= 59:
            print('你的分数是%d,不及格' % int(score))
        elif 30 <= int(score) <= 49:
            print('你的分数是%d,较差' % int(score))
        elif 1 <= int(score) <= 29:
            print('你的分数是%d,很差' % int(score))
        else:
            print('你的分数是{}'.format(score))
else:
    print('请输入正确的分数!')

 

原创视频,版权所有,未经允许,切勿转载,违者必究!
回顶部