标签:循环语句 code highlight bsp inpu n+1 pass end put
1、利用while循环语句, 输出:1,2,3,4,5,6,8,9,10
n = 0 while n<10: n = n+1 if n==7: pass else: print(n) print("end")
2、输出1-100内的所有奇数
n=0 while n<100: n=n+1 if n%2==0: pass else: print(n) print("end")
3、输出1-100内的所有偶数
n=0 while n<100: n=n+1 if n%2==0: print(n) print("end")
4、求1-100的和
n = 0 m = 1 while m < 101: n = n + m m = m + 1 print(n)
5.求1-2+3-4+5 ... 99的所有数的和
n = 0 m = 0 while m < 100: m = m + 1 if m % 2 == 0: n = n - m else: n = n + m print(n)
用户名密码登录三次机会(本段代码有bug)
n=input("请输入账号") m=input("请输入密码") t=0 while t<4: if n==‘qwe‘ & m==‘123‘: print("登录成功") else: print("登录失败,请重新输入") t=t+1
标签:循环语句 code highlight bsp inpu n+1 pass end put
原文地址:https://www.cnblogs.com/xiongwy/p/9211456.html