标签:sum col and 输入 密码 put pass while pre
1、使用while循环输入1 2 3 4 5 6 ... 8 9 10
count = 1 while count <= 10: print(count) # count = count + 1 count += 1
2、使用while循环输入1 2 3 4 5 6 8 9 10
count = 1 while count <= 10: if count == 7: print(‘ ‘) else: print(count) count += 1
3、使用while循环输入1 2 3 4 5 6 8 9 10
方法一、
count = 0 while count < 10: count += 1 if count == 7: continue print(count)
方法二、
count = 0 while count < 10: count += 1 if count == 7: pass else: print(count)
4、输出1-100内所有的奇数
方法一、
count = 0 while count < 100: count += 1 if count % 2 == 1: print(count)
方法二、
count = 1 while count < 99: count += 2 print(count)
5、求1-2+3-4+5...+99的所有数的和
count = 1 sum = 0 while count < 100: if count % 2 == 1: sum += count else: sum -= count count += 1 print(sum)
6、用户登录(三次机会重试)
count = 0 while count < 3: name = input("请输入用户名") password = input("请输入密码") if name == ‘mahelin‘ and password == ‘250238linlin‘: print("登录成功") elif count == 2: print("登录失败") else: print("登录失败请重试") count += 1
标签:sum col and 输入 密码 put pass while pre
原文地址:https://www.cnblogs.com/qingmuzi/p/12508875.html