标签:int 使用 pass str user 锁定 管理员 输出 循环
1,使用while循环输入1 2 3 4 5 6 8 9
n = 1 while n <= 9: if n == 7: pass else: print(n) n += 1
2,求1-100的所有数的和
sum = 0 num = 1 while num <= 100: sum += num num += 1 print(sum)
3,输出1-100内的所有奇数
num = 1 while num <= 100: if num % 2 != 0: print(num) num += 1
4,输出1-100内的所有偶数
num = 1 while num <= 100: if num % 2 == 0: print(num) num += 1
5,求1-2+3-4+5-6.。。99的所有数的和
sum = 0 num = 1 while num < 100: if num % 2 == 0: sum -= num else: sum += num num += 1 print(sum)
6,用户登录(三次机会重试)
username = "123456" passward = "123456" n = 3 while n > 0: n -= 1 user_name = input("请输入用户名") pass_ward = input("请输入密码") if user_name == user_name and passward == pass_ward: print("登录成功") break else: if n != 0: print("登陆失败,用户名和密码不匹配请验证后再次尝试,你还有" + str(n) + "次机会!") else: print("你的账户已锁定,请与管理员联系!")
标签:int 使用 pass str user 锁定 管理员 输出 循环
原文地址:https://www.cnblogs.com/xiaozhen522/p/12449670.html