死循环:
条件循环:
练习
第一题:
n = 1 while n < 11: if n == 7: pass else: print(n) n = n + 1 print('-----end-----')
第二题:
n = 1 d = 0 while n <= 100: d = d + n n = n + 1 print(d) print('-----end-----')
第三题:
n = 0 while n < 100: n = n + 1 if n % 2 != 0: print(n) else: pass print('-----end-----')
第四题:
n = 0 while n <= 100: n = n + 1 if n % 2 == 0: print(n) else: pass print('-----end-----')
第五题:
n = 1 d = 0 while n < 100: d = n - (n + 1) + ( n + 2) n = n + 1 print(d) print('-----end-----')
第六题:
number = 0 while number < 3: user = input('>>>') pwd = input('>>>') if user == '10086' and pwd == '888': print('信息正确') print('欢迎登陆...') break else: print('你输入的信息错误,请重新输入...') number = number + 1
答案:
6