outputs all odd and even numbers from 1 to 100:
num = 1 while num <=100:if num%2 = = 0:print (num) num + = 1cai num = 1 while num <=100:if nu m%2 = = 1:print (num) num + = 1
Two ways to guess Age games:
Age = 50flag = truewhile flag: user_input_age = int ( Input ("Age is:")) if user_input_age == age: print ("Yes") flag = false elif user_input_age > age: print ("Is bigger") else: Print ("Is smaller") print ("End") age = 50while true: user_input_age = int (Input ("Age is:")) if user_input_age == age: print ("Yes") break elif user_input_age > age: print ("Is bigGer ") else: print (" Is smaller ") Print ("End")
Break statements and continue statements.
The end statement in print:
#print ("Hello World", end= "__") # \ r \ n \r#print ("Hello World", end= "__") #print ("Hello World", end= "__") NUM1 = 0whil E Num1<=5:print (num1,end= "_") num2 = 0 while Num2<=7:print (num2,end= "-") num2+=1 Num1+=1 print () # print (end= "\ n") #0_0 -1-2-3-4-5-6-7-#1_0 -1-2-3-4-5-6-7-
Output # number, specify a long rectangle:
height = Int (input ("Height:")) width = Int (input ("width:")) Num_height = 1 while num_height <= height:num_width = 1 While Num_width <= width:print ("#", end= "") Num_width + = 1 print () Num_height + = 1
Python while loop