1, conditional
1.1, individual determination: if
# Assigned to the number of gems stonenumber = 6 # condition: If the number of stones you have six or more IF stonenumber> = 6 : # Result: 'You have the power to destroy the universe' results Print ( ' you have to destroy the universe power ' )
2.2, two-way judgment: if ... else ...
# Assignment: assign the number of gems stonenumber = 3 # condition: If the number of stones you have six or more IF stonenumber> = 6 : # Result: 'You have the power to destroy the universe' results Print ( ' you have the power to destroy the universe ' ) # condition: when the assignment if the conditions are not satisfied, the command execution of the else the else : # result:' look for the soul gem 'results Print ( ' with card magic got me Waugh Mill Star seeking the soul gem ' )
In if ... else conditional statements, IF and else each hold together, to form two different code blocks. Indicates the conditions and other conditions mutually exclusive relationship - if not satisfied if the conditions on the implementation else other conditions .
About if ... else ... knowledge points to finish up here, we summarize what if ... else ... knowledge statements.
1.3, and more to determine: if ... elif ... else ...
When the judgment condition of more than 3 , the plurality of intermediate conditions can be used elif .
# Assigned to the number of gems stonenumber = 5 # condition: If the number of stones you have six or more IF stonenumber> = 6 : # Result: 'having the power to destroy the universe' results Print ( ' you have to destroy the universe power ' ) # condition: if you want to stay number of stones in five or less, at least one elif 0 <stonenumber <= 5 : # result:' scarlet witch need to personally destroyed the soul gem on the forehead visual hallucinations' results print ( ' scarlet witch need to personally destroyed heart jewel phosphenes forehead ' ) # condition: when the assignment condition is not satisfied if and elif, the else execute the command, the number of gemstones is 0 the else : # result: 'surprising required captain reversal of the future 'results Print ( ' we need to reverse the future captain Marvel ' )
We summarize the knowledge elif:
2, if nested
if nested application scenarios, simply, is this: In the case of basic conditions are met, then additional conditional basis under the conditions.
historyscore = 26 IF historyscore> = 60 : Print ( ' you've passed ' ) IF historyscore> = 80 : Print ( ' you are very good ' ) the else : Print ( ' You're just like a general ' ) the else : Print ( ' failing ' ) IF historyscore <30 : Print ( ' Learn slag ' ) the else : Print ( ' You can rescue ' ) Print ( ' end of program ' )