Go with the Flow

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed. Go with the Flow

(This course assumes familiarity with the material presented in unit 1:python syntaxand unit 2:strings & Console out Put. From here on out, take for granted this each new course assumes knowledge of the material presented in the previous course S.)

Noticed that the Python programs we ' ve been writing so far has had sort of one-track minds. They compute the sum of the numbers orprintSomething to the console, but they don ' t has the ability to pick one outcome over Another-say, add, numbers if their s Um is less than, or insteadprintThe numbers to the console without adding them if their sum is greater than 100.

Control Flow allows us to has these multiple outcomes and to select one based on "What's Going On" the program. Different outcomes can be produced based on user input or any number of factors in the program ' s Environment. (The environment is the technical name to all of the Variables-and their values-that exist in the program at a given time.)

"Def clinic (): print" You ve just entered the clinic! "    Print "Does the door on the left or the right?" Answer = Raw_input ("Type left or right and hit ' Enter '."). Lower () if answer = = "Left" or answer = = "L": print "This is the Verbal abuse the guest, you heap of parrot droppings    !"    Elif answer = = "right" or answer = = "R": print "Of course this is the Argument the box, I ' ve told you that already!" Else:print "didn" t pick left or right!        Try again. " Clinic () "# #上面采用的是递归. The efficiency of recursion is lower.    Change to Cycle Def clinic (): print "You ve just entered the clinic!"    Print "Does the door on the left or the right?"    While true:answer = Raw_input ("Type left or right and hit ' Enter '.")  ). Lower () if answer = = "Left" or answer = = "L": print "This is the Verbal abuse the guest, you heap of parrot            Droppings! " Break Elif Answer = = "right" or answer = = "R": print "Of course this is the Argument, I ' ve told YOU that already! " Break Else:print "didn ' t pick left or right! Try again. " Clinic ()


Related Article

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.