输出1 2 3 4 5 6 8 9 10
#!/bin/usr/env python n = 1; while n<11: if n == 7: pass else: print(n) n = n+1 print("---end---")
输出1-100内的奇数
#!/bin/usr/env python n = 1; while n<101: if n % 2 == 0: pass else: print(n) n = n+1 print("---end---")
或
#!/bin/usr/env python n = 1; while n<101: print(n) n = n+2 print("---end---")
求1-100的和
#!/bin/usr/env python n = 1 s = 0 while n<101: s += n n = n + 1 print(s) print("---end---")
求1-2+3...-100的值
#!/bin/usr/env python n = 1 s = 0 while n<101: if n%2==0: s -= n else: s += n n = n + 1 print(s) print("---end---")
用户登录三次机会重试
#!/bin/usr/env python count = 1 while count < 4: first = input("输入密码:") if first == "root": print("输入正确") break; else: count = count + 1 if count == 4: print("输入超过三次") break; print("---end---")
原文地址:https://www.cnblogs.com/holdononedream/p/10837832.html
时间: 2025-01-13 10:17:15