python 练习题
1、使用while循环输入1 2 3 4 5 6 8 9 10
count = 0 while count < 10: count =count + 1 if count < 7 or count > 7 : print(count) else: continue;
2、求1-100所有的和
count = 1 nmt = 0 while count <= 100: nmt = nmt + count count += 1 print(nmt)
3、输出1-100所有的奇数
count = 1 while count < 100: count = count + 1 if (count% 2 ) == 1: print(count)
4、输出1-100所有的偶数
count = 1 while count <= 100: count = count + 1 if (count % 2) == 0: print(count)
5、求1-2+3-4+5...+99的结果
count = 1 sum = 0 while count < 100: if count % 2 == 0: sum = sum - count else: sum = sum + count count += 1 print(sum)
5、用户登录,3次重试机会
count= 0 while count < 3: account = input ('请输入您的账号:') password = input('请输入您的密码:') if account == 'miss' and password == '123': print('登录成功') else: print('输入密码错误,您还有三次重试机会,三次输入错误后,会锁定账号!') count += 1 if count == 3: print('您的账号被锁定,请重置联系管理员重置密码。')