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 orprint
Something 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 insteadprint
The 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 ()