008、if 语句 (if , elif ,else)

 

if  语句 (if  , elif ,  else)

if 判断条件1:
    执行语句1……
elif 判断条件2:
    执行语句2……
elif 判断条件3:
    执行语句3……
else:
    执行语句4……

score = int(input('请输入您的成绩:'))

if 70 >= score >= 60:
    print('及格')
elif 80 >= score > 70:
    print('良好')
elif score > 80:
    print('优秀')
else:
    print('不及格')
View Code

执行结果如下:

请输入您的成绩:55
不及格

Process finished with exit code 0
View Code

 

示例代码2 :

today = input('今天是星期几:')
days = ['星期一', '星期二', '星期三', '星期四', '星期五', ['星期六', '星期日']]

if today in days[5]:
    print('今天是周末,休息。')
elif today in days[0:5]:
    print('今天是上班日。')
else:
    print('输入有误。')
View Code

执行结果如下:

D:\SkyWorkSpace\WorkSpace\Pytest\Temp\day06\venv\Scripts\python.exe D:/SkyWorkSpace/WorkSpace/Pytest/Temp/day06/gggg/test_2.py
今天是星期几:啊飞洒发生
输入有误。

Process finished with exit code 0
View Code

 

posted @ 2021-07-25 22:52  空-山-新-雨  阅读(593)  评论(0编辑  收藏  举报