# 1、使用while循环输入 1 2 3 4 5 6 8 9 10 count = 1 while count<11 : #使用while语句循环输入123...10 if count == 7: # 使用if语句中的pass,将7跳过不输入 pass else: print(count) count +=1 print('-------end-------') ################## # 2、求1-100的所有数的和 temp = 1 sum = 0 while temp <101: sum = sum+temp temp +=1 print(sum) print('-------end-------') ################# # 3、输出 1-100 内的所有奇数 count = 1 while count<101: n = count %2 if n==0: pass else: print(count) count +=1 print('-------end-------') # 4、输出 1-100 内的所有偶数 count = 1 while count < 101: n = count%2 if n==0: print(count) else: pass count += 1 print('-------end-------') ################ # 5、求1-2+3-4+5 ... 99的所有数的和 count = 1 sum1 = 0 sum2 = 0 sum = 0 while count <100: if count %2: sum1=sum1+count else: sum2 = sum2 +count sum = sum1 - sum2 count += 1 print (sum) print('-------end-------') m =1 s=0 while m<100: j = m%2 if j==0: s = s -m else: s = s +m m = m +1 print(s) print('-------end-------')
#6.用户登陆(三次机会重试) count = 0 while count<3: user_id = input('请输入用户名:') password = input("请输入密码:") if user_id =='mada' and password == '0930': print('登录成功') break else : print('用户名或密码错误,请重新输入') count +=1