1、使用while循环输入1 2 3 4 5 6 8 9 10
#使用while循环输入1 2 3 4 5 6 8 9 10n = 1while n <= 10: if n != 7: print (n) n += 1
2、求1—100的所用数的和
#求1—100的所用数的和n = 1m = 0while n <= 100: m += n n += 1print (m)
3、输出1—100内的所用奇数
#输出1—100内的所用奇数n = 1while n <= 100: if n%2 != 0: print (n) n += 1
4、输出1—100内的所用偶数
#输出1—100内的所用偶数n = 1while n <= 100: if n%2 ==0: print (n) n += 1
5、求1-2+3-4+5-6+7-8 ... 99的所用数的和
#求1-2+3-4+5-6+7-8 ... 99的所用数的和n = 1m = 0while n <100: if n%2 != 0: m += n else: m -= n n += 1print (m)
6、用户登陆(有三次机会重试)
#用户登陆(有三次机会重试)n = 1while n <=3: name = input(“please enter name") pwd = input ("please enter password") if name == "kingo" and pwd == "kingo": print ("welcome, kingo!") break; else: print ("name or password is wrong!") n += 1else: print ("the times is over!")