Judgment and nested if

Conditional three forms:

1. Analyzing way: if

. 1  IF Age> 18 is :
 2      # conditions 
. 3      Print ( " you have grown up, the independence ' )
 4      # something

2. Bidirectional judgment: if ... else ...

1  if Age> 18 :
 2      # condition 
3      Print ( ' You've grown up, the independence ' )
 4      # do something 
5  the else :
 6      # when the condition is not satisfied if 
7      Print ( ' You are young, you need to listen more if the parents ' )
 8      # do whatever point

3. More to determine: if ... elif ... else ...

In judging more than three or three of the conditions, we need to determine multi-command

Multi-directional command logic judgment: If the condition is not satisfied if, in order to see whether it meets the conditions elif, if the conditions are not satisfied elif, else the command is executed.

Then, when the condition is determined more than 3, a plurality of intermediate conditions can be used elif.

1  # assigned to the number 
2 Number =. 5
 . 3  
. 4  # Condition: If the number you have 6 or more 
. 5  IF Number> =. 6 :
 . 6      
. 7      # Results: The results show 'having the power to destroy the universe apos 
. 8      Print ( ' you have the power to destroy the universe ' )
 9      
10  # condition: if you want to stay number of stones in five or less, at least a 
11  elif 0 <number the <= 5 :
 12  
13      # result: 'scarlet witch need to personally destroyed heart jewel phosphenes forehead 'results 
14      Print ( ' scarlet witch need to personally destroyed heart jewel phosphenes forehead ' )
 15  
16  #Condition: When the assignment condition is not satisfied if and elif, the else execute the command, the number of gemstones is 0 
. 17  the else :
 18 is  
. 19      # Result: 'need to reverse the future Captain Marvel' result 
20 is      Print ( ' need to reverse the future Captain Marvel ' )

 

if nested execution order:

 

 

. 1 historyscore = 26 is
 2  IF historyscore> = 60 :
 . 3      Print ( ' You have failed ' )
 . 4      IF historyscore> = 80 :
 . 5          Print ( " you are very good " )
 . 6      the else :
 . 7          Print ( " you just like a general ' )
 8  the else :
 . 9      Print ( ' fail ' )
 10  Print ( " end of program " )

 

Guess you like

Origin www.cnblogs.com/String-song/p/11927890.html