Python之路第三篇——Python入门练习

 1 # 1、使用while循环输入 1 2 3 4 5 6  8 9 10
 2 count = 1
 3 while count < 11: # 这里如果是 count <= 10 结果是可以的,但是会多个字节,所以尽量瘦身
 4     if count == 7:
 5         pass
 6     else:
 7         print(count)
 8     count += 1
 9 print("--------end--------")
10 # 2、求1-100的所有数的和
11 n = 1
12 s = 0
13 
14 while n < 101:
15     s += n
16     n += 1
17 print(s)
18 print("--------end--------")
19 # 3、输出 1-100 内的所有奇数
20 j = 0
21 while j < 101:
22     j += 1
23     if j % 2 == 0:
24         pass
25     else:
26         print(j)
27 print("--------end--------")
28 # 4、输出 1-100 内的所有偶数
29 p = 0
30 while p < 101:
31     p += 1
32     if p % 2 == 0:
33         print(p)
34 print("--------end--------")
35 # 5、求1-2+3-4+5 ... 99的所有数的和
36 n = 1
37 s = 0
38 while n < 100:
39     rem = n % 2
40     if rem == 0:
41         s = s - n
42     else:
43         s = s + n
44     n += 1
45 print(s)
46 print("--------end--------")
47 # 6、用户登陆(三次机会重试)
48 count = 0
49 while count < 3:
50     user_name = input("input your name >>>:")
51     user_psd = input("input your password >>>:")
52     if user_name == "python" and user_psd == "123123":
53         print("welcome")
54         break
55     else:
56         print("try again")
57         count += 1

 

posted @ 2018-02-24 15:54  千行路  阅读(80)  评论(0编辑  收藏  举报