首先得先編一下程式員必須編的程式——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')
複制