1. Use while loop input 1 2 3 4 5 6 8 9 10
Code:
0 While I <: 1 if7: continue Print (i)
Results:
2. For all numbers of 1-100
Code:
i = 0sum = 0while i<=100:i+=1sum = sum+iprint (sum)
Results:
3. All odd numbers in output 1-10:
i = 0while I < 9:i + = 1if I% 2 = = 1:print (i)
Results:
4. All even numbers in the output 1-100
0 while One : 1 if 2 0 : print (i)
Results:
5, Beg 1-2+3-4+5 ... 99 of all numbers of the and
i =0J_sum=0O_sum=0sum=0 whileI < About: I+=1 ifI2==1: J_sum= J_sum +IifI2==0: O_sum= O_sum +I sum=j_sum-o_sumprint (j_sum) print (o_sum) print (sum)
Results:
6. User Login (three chance retry)
A = 0while a < 3:a +=1username = input ("Please enter your user name:") Password = input ("Please enter your password:") if username = = ' Wang ': if password = = ' n An ':p rint ("Login succeeded") Breakelse:print ("Login Failed") else:print ("Rewrite input")
Results:
#输入错误:
#输入成功:
Python Introductory Exercises