Note: The if statement code is executed from top to bottom, and when it reaches the statement that satisfies the condition, the code will stop executing downward.
Note: if statements are followed by a colon
score = int (input("score:")) if score > 90: print("A") elif score > 80: print("B") elif score > 70: print("C") elif score > 60: print("D") else score < 60: print("Go for it, kid.")
Additional knowledge:Python if statements and conditional tests (and, or, in, not in)
、or、in、not in
''' Conditional Testing ''' # Individual condition tests age0 = 22 print(age0>=22) # True #Multiple condition tests and age0 = 22 age1 = 18 print(age0>=21 and age1>=21) #False #Multiple condition tests or print(age0>=21 or arg0>=21) #True #in and not in (checking whether a particular value is in the list) fruits = ['apple','banana','orange'] print('apple' in fruits) #True print('apple' not in fruits) #False
statement
''' Simple if statements (containing only a test and an action) ''' height = 1.7 if height>=1.3: print('High')
''' if-else ''' height = 1.8 if height<=1.4: print('Free tickets') else: print('Unanimous vote') #Final Output Unanimous Vote
''' if-elif ''' height = 1.5 if height>=1.4: print('Heh heh.') elif height>=1.3: print('Huh.') #Final output hehehe
''' if-elif-else ''' height = 1.8 if height<=1.4: print('Free tickets') elif height>1.4 and height<=1.7: print('Half Ticket') else: print('Unanimous vote') #Final Output Unanimous Vote
The above use of this Python multi-branch if statement is all that I have shared with you.