首先得先编一下程序员必须编的程序——Hello World……(这应该是程序员情结。。。)
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 12:26'
5 _author_ = 'Colby'
6 print('Hello World!')
一、输出1,2,3,4,5,6,8,9,10
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 7:49'
5 _author_ = 'Colby'
6 count = 0
7 num = 1
8 while count < 10:
9 if num == 7:
10 pass
11 else:
12 print(num)
13 num += 1
14 count += 1
二、求1~100的和
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 7:52'
5 _author_ = 'Colby'
6 num = 1
7 count = 0
8 while num < 101:
9 count = count + num
10 num += 1
11 print(count)
三、求1-2+3-4+5...+99的值
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 7:54'
5 _author_ = 'Colby'
6 num = 1
7 count = 0
8 while num < 100:
9 temp = num % 2
10 if temp == 0:
11 count = count - num
12 else:
13 count =count + num
14 num += 1
15 print(count)
四、输出1~100所有的奇数
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 7:58'
5 _author_ = 'Colby'
6 num = 1
7 while num < 101:
8 temp = num % 2
9 if temp == 0:
10 pass
11 else:
12 print(num)
13 num += 1
五、输出1~100所有的偶数
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 8:00'
5 _author_ = 'Colby'
6 num = 1
7 while num < 101:
8 temp = num % 2
9 if temp == 1:
10 pass
11 else:
12 print(num)
13 num += 1
六、用户登录(三次登录机会,用户名和密码自己设定)
1 #coding=utf-8
2 #Version:python3.7.0
3 #Tools:Pycharm 2017.3.2
4 _date_ = '2018/12/30 8:01'
5 _author_ = 'Colby'
6 #import os
7 num = 1
8 while num < 4:
9 temp = 3 - num
10 user_id = input("请输入用户名:")
11 user_passwd = input("请输入密码:")
12 if user_id == "zjx" and user_passwd == "123456":
13 print("登录成功!")
14 break
15 else:
16 if temp > 0:
17 print("登录错误!您还可以输入%d次!"%(temp))
18 else:
19 print("已被锁定!请30秒后重新登录!")
20 num += 1
21 #os.system('cls')