Guibs's Python learning _while&input

Source: Internet
Author: User
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)!

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.