【python 基础练习】
1、使用while循环输入 1 2 3 4 5 6 8 9 10
a = 0 while a<10: a = a + 1 if a == 7: continue print(a)
2、求1-100的所有数的和
n = 1 sum = 0 while n <= 100: sum = sum + n n = n+1 print(sum)
3、输出 1-100 内的所有奇数
n = 1 while n <= 100: if n%2 != 0: print(n) n = n+1
4、输出 1-100 内的所有偶数
n = 1 while n <=100: if n%2==0: print(n) n = n+1
5、求1-2+3-4+5 ... 99的所有数的和
n = 1 sum = 0 while n < 100: if n%2==1: sum = sum + n else : sum = sum-n n=n+1 print(sum)
6、用户登陆(三次机会重试)
n=0 while n<3: username = input('请输入用户名:') password = input("请输入密码:") if username=='张三' and password=='123456' : print("成功登录!!!") break n = n+1 print("用户名或密码错误")