测试题目摘自
一、使用while循环输入1-10,其中不包括7
1 number = 02 while number<10:3 number +=14 if number == 7:5 continue6 print(number)
二、求1-100的所有数的和
1 count = 12 sum = 03 flag =True4 while flag:5 sum = sum + count6 count += 17 if count > 100:8 break9 print('1-100的总和是:',sum)
三、输出1-100内的所有奇数
1 odd = 12 while odd <=100:3 print(odd)4 odd += 2
四、输出1-100内的所有偶数
1 even = 02 while even <=100:3 even += 24 if even > 100:5 continue6 print(even)
五、求1-2+3-4+5...99的所有数的和
1 odd = 1 2 even = 2 3 odd_sum = 0 4 even_sum = 0 5 while odd < 100: 6 odd_sum = odd_sum + odd 7 odd += 2 8 while even < 100: 9 even_sum = even_sum + even10 even += 211 print('odd_sum:',odd_sum,'even_sum:',even_sum)12 count_sum = odd_sum - even_sum13 print("1-2+3-4+5...99的所有数的和是:",count_sum)
六、用户登陆(三次机会重试)
count_number = 3name = 'admin'password = 'admin'flag = Truewhile flag: user_name = input("请输入你的用户名:") user_password = input("请输入你的登录密码:") if user_name==name and user_password==password: print('用户名与登录密码输入正确,用户登录成功') break if count_number == 3: print('用户名或登录密码输入不一致,你还有两次机会') elif count_number == 2: print('用户名或登录密码输入不一致,你还有一次机会') else: print('用户名或登录密码输入不一致,你的机会已经用完,请过5分钟后再试') count_number -= 1 if count_number < 1: break