python要开始记录了20181125

 1 print('1、使用while循环输入 1 2 3 4 5 6     8 9 10')
 2 i = 1
 3 while i < 10:
 4     i += 1
 5     if i == 7:
 6          continue       #print(' ')这两个可以替换一下,看看不同的效果
 7     else:
 8         print(i)
 9 
10 
11 print('2、求1-100的所有数的和')
12 i = 0
13 sum = 0
14 while i < 100:
15       i += 1
16       sum = sum + i
17       print(sum)
18 
19       
20 print('3、输出 1-100 内的所有奇数')
21 i = 0
22 while i < 100:
23     i += 1
24     if i %2 != 0:
25         print(i)
26         
27 
28 print('4、输出 1-100 内的所有偶数')
29 i = 0
30 while i < 100:
31     i += 1
32     if i %2 == 0:
33         print(i)
34 
35 print('5、求1-2+3-4+5 ... 99的所有数的和')
36 i = 0
37 sum = 0
38 j = -1
39 while i < 99:
40     i += 1
41     if i %2 != 0:
42         sum = sum + (i * (-j))
43     if i %2 == 0:
44         sum = sum + (i * j)
45 print(sum)
46 
47 
48 
49 
50 print('6、用户登陆(三次机会重试)')
51 i = 0
52 oppo = 3
53 name = 'allison'
54 password = '123456'
55 while oppo > 0:
56     na = input('请输入用户名:')
57     pw = input('请输入密码:')
58     i += 1
59     oppo = 3 - i
60     if na == name and pw == password:
61         print('输入正确')
62         break
63     elif na != name or pw != password:
64         print('输入错误, 还有%d次机会'%(oppo))
65         if oppo == 0:
66             answer = input('再试试?Y')
67             if answer == 'Y':
68                 oppo == 3
69                 break
70     else:
71         if oppo == 0:
72             print('机会已用完')

猜你喜欢

转载自www.cnblogs.com/allison-aichipingguo/p/10017036.html
今日推荐