1. use while circulating 1 2 3 4 5 6 8 9 10
count=0 while count <10: count+=1 print(count)
2. Sum all numbers from 1 to 100
count=0 total=0 # Define two variables while count <=100: total +=count # The total's count needs to be added cumulatively every time the loop is performed. count=count+1 # Each time we loop, the count needs to be increased by 1. print(total) #output result
3. Output all odd numbers within 1-100
count=1 while count<=100: if count%2 != 0: print(count) count+=1
4. Output all even numbers within 1-100
count=1 while count<=100: if count%2 != 1: print(count) count+=1
5. User login (three retries)
while count<3: name=input("Please enter your user name.") password=input("Please enter the password.") if name=="huxiaohui" and password=="123456": print("You got it.") break else: print("Wrong. Do it again.") count+=1
To this point this article on 5 about python basic while loop practice questions on the article is introduced to this, more related to while loop practice questions in python content please search for my previous articles or continue to browse the following related articles I hope you will support me more in the future!