Python学习之路
Posted wkp19991203
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习之路相关的知识,希望对你有一定的参考价值。
1 ‘‘‘ 2 输出1~6 8~10 3 方法一: 4 count = 0 5 while count < 10: 6 count +=1 7 if count == 7: 8 print(‘ ‘) 9 else: 10 print(count) 11 12 方法二: 13 count = 0 14 while count < 10: 15 count = count+1 16 if count == 7: 17 continue 18 else: 19 print(count) 20 21 输出1~100所有数之和 22 sum = 0 23 count = 1 24 while count < 101: 25 sum = sum + count 26 count = count + 1 27 print(sum) 28 29 输出1~100所有的奇数 30 方法一: 31 count = 1 32 while count < 101: 33 print(count) 34 count = count + 2 35 36 方法二: 37 count = 1 38 while count < 101: 39 if count % 2 == 1: 40 print(count) 41 count = count + 1 42 43 输出1~100所有数之和 44 sum = 0 45 count = 1 46 while count <= 100: 47 sum = sum + count 48 count = count + 1 49 print(sum) 50 51 输出1~100所有胡偶数 52 方法一: 53 count = 1 54 while count < 101: 55 if count % 2 == 0: 56 print(count) 57 count = count + 1 58 59 方法二: 60 count = 0 61 while count < 101: 62 print(count) 63 count = count + 2 64 65 输出1-2+3-4+5...99的所有数的和 66 sum = 0 67 count = 1 68 while count < 100: 69 if count % 2 ==0: 70 sum = sum - count 71 else: 72 sum = sum + count 73 count = count + 1 74 print(sum) 75 76 方法二: 77 sum = 0 78 count = 1 79 while count < 100: 80 if count % 2 == 0: 81 sum = sum - count 82 elif count % 2 == 1: 83 sum = sum +count 84 count = count + 1 85 print(sum) 86 87 用户登录(三次机会重试) 88 count = 0 89 while count < 3: 90 username = input(‘请输入账号: ‘) 91 password = int(input(‘请输入密码: ‘)) 92 if username == ‘吴鲲鹏‘ and password == 123456: 93 print(‘登录成功‘) 94 break 95 else: 96 print(‘登录失败请重新登录‘) 97 count = count + 1 98 ‘‘‘
以上是关于Python学习之路的主要内容,如果未能解决你的问题,请参考以下文章