python——if和elif语句练习

 1 #!/usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 #例子1
 4 username = input("请输入命令:")
 5 password = input("请输入密码:")
 6 
 7 if username == "lipc" and password == 123:
 8     print("登陆成功")
 9 else:
10     print("登陆失败")
11 
12 
13 #例子2
14 fen = int(input("请输入你的成绩:"))
15 if 0 < fen <= 59:
16     print("不及格")
17 elif 60 <= fen <= 79:
18     print("较好")
19 elif 80 <= fen <= 99:
20     print("优秀")
21 elif fen == 100:
22     print("满分")
23 else:
24     print("无效的输入")
25 
26 
27 #例子3
28 year = int(input("请输入年:"))
29 month = int(input("请输入月份:"))
30 if  month == 1 or  month == 3 or  month == 5 or  month == 7 or  month == 8 or  month == 10 or  month == 12:
31     print("此月有 31 天。")
32 elif  month == 4 or  month == 6 or  month == 9 or  month == 11:
33     print("此月有 30 天。")
34 elif month == 2 and ((year % 4==0 and year % 100!=0) or (year % 400==0)):
35     print('29天')
36 else:
37     print('28天')
posted @ 2019-12-26 19:41  Leonardo-li  阅读(820)  评论(0编辑  收藏  举报