Q1. 使用while循环输入:1 2 3 4 5 6 8 9 10
count = 0 while count < 10: count = count + 1 if count == 7: continue print(count)
Q2. 求1-100所有数的和
#1-100求和 first = 1 sum = 0 while first <= 100: sum += first first += 1 print(sum)
count = 0 while count < 100: count = count + 1 s=((count+1)*count/2) print(s)
Q3.输出1-100内所有奇数
Q4 输出1-100内所有偶数
Q3
count = 0 while count < 100: count = count + 1 if count %2 != 0: #奇数 print(count)
Q4
count = 0 while count < 100: count = count +1 if count %2 == 0: print(count)
Q5 #求1-2+3-4...99 a = 1 sum = 0 while a < 100: if a %2 == 0: #even sum = sum - a else: sum = sum + a #odd a = a + 1 print(sum)
#用户登陆三次机会 count=0 while count < 3: username = input('enter your name') password = input ('enter your password') if username == 'Nero'and password == '123': print('success') break else: count=count+1 print('error')