Guibs's Python learning _while&input
# while and input# input () # input () receives a parameter: the hint or description to be displayed to the user message = Input ("Tell me what you want to say to me, I'll repeat your words ~\n") print ("You say:" + message) # Use INT () to get a numeric input of age = input ("How old are you? \ n") print (' So. You next year ' + STR (int. + 1) + ' up ') # using while loop Current_number = 1while Curre Nt_number <= 5:print (current_number) Current_number + = 1 2 3 4 * Use flag to control loop activity = Truenum = 1while Activi Ty:print ("Hello") num + = 1 if num = = 3:activity = false# Hello hello# use break to exit loop Current_number = 1whi Le current_number <= 5:if current_number! = 3:print (current_number) Current_number + = 1 Else: break# 1 * Use continue to jump into the next loop Current_number = 1while current_number <= 5:if current_number! = 3:print (current_number) Current_number + = 1 Else:current_number + = 1 continue# 1 2 4 * Using while processing lists and dictionaries Unconfirmed_users = [' Alice ', ' guibs ', ' Mike ']confirmed_users = []print ("unconfirmed list:" + str (unconfirmed_users)) print ("Confirmed list : "+ str (confirmed_users))While unconfirmed_users:current_user = Unconfirmed_users.pop () confirmed_users.append (current_user) print (Curren T_user + "confirmed") print ("Unconfirmed list:" + str (unconfirmed_users)) print ("Confirmed list:" + str (confirmed_users)) # Delete all list elements that contain a specific value pets = [' d og ', ' cat ', ' dog ', ' goldfish ', ' rabbit ']while ' dog ' in Pets:pets.remove (' dog ') print (pets) # Populate dictionary with user input responses = {}po lling_active = truewhile Polling_active:name = input ("What's name \ n") response = input ("What do you like \ n") responses[name] = Res Ponse repeat = input ("Do you want to continue adding? Yes/no \ n") if repeat = = ' no ': Polling_active = falseprint (responses)
The above is guibs Python learning _while&input content, more relevant content please pay attention to topic.alibabacloud.com (www.php.cn)!