Case: Rating the given score, the following are three options:
score = Int (input (' Please enter a fraction ')) #第一种方案if >= score >=: print (' A ') if > score >=: print (' B If > Score >=: print (' C ') if 0 > Score >=: print (' D ') Else: print (' Input error! ‘)
score = Int (input (' Please enter a fraction ')) #第二种方案if >= score >=: print (' A ') Else: if > Score >= 80:
print (' B ') else: if > Score >=: print (' C ') else: if- > Score >= 0: Print (' D ') else: print (' Input error! ‘)
score = Int (input (' Please enter a fraction ')) #第三种方案if >= score >=: print (' A ') elif > Score >=: print ( ' B ') elif > Score >=: Print ( ' C ') elif > score >= 0: print (' D ') Else: print (' Input error! ‘)
Of the above three scenarios, the third one has the lowest time complexity.
#注意 Hang Else
For example, a beginner in C can easily be fooled by a bit of code.
if (Hi > 2) if (Hi > 7) printf (' good ') Else printf (' Fuck ')
- Conditional expressions (Ternary operators)
syntax: x if condition else y
Assert this keyword we call assertions, when the condition behind this keyword is false when the program automatically crashes, throwing Assertionerror exceptions.
As An example ,
Assert 3 > 4
This statement is often used to set a checkpoint in a program, which is used to debug a program.
python[Little Turtle 008 Great branches and Loops 2]