Conditionals & Control Flow>I Got 99 Problems, But a Switch Ain't One>


#1

I just want to clear confusion in the Topic: "Conditionals & Control Flow>I Got 99 Problems, But a Switch Ain't One" that it is mentioned here:

"the elif statement is only checked if the original if statement if False."

I am understanding this in 2 ways:

  1. We have to give the if condition so "False", so that it can check the elif condition code block in the program.
  2. Or if we had given the True condition in the if, then according to as mentioned "the elif statement is only checked if the original if statement if False.", then it will not check the elif condition or it depends upon the user input if user inputs wrong answer.

Please Help me in this.


#2

this simply means elif is only checked when if will evaluate to false? Its a reminder of how if/elif statement work. When if evaluate to True, the condition at elif is never checked


#3

So, if will evaluate to false, if the user inputs the wrong answer..??


#4

for this condition;

if answer < 5:

it will be false if answer is 5 or greater


#5

I thought we have to make the if statement always false, So, it can check the elif. So, it depends upon the scenario that for the above condition, if user inputs the 4, then the condition will be true and elif will be not checked and if the answer inputted at 6, then the elif will be executed.


#6

what? No.

this was only a reminder how if/elif works, it doesn't say you always have to make if false


#7

ok got it. thank you @stetim94


#8

The elif statement will run if the IF is false.So before going for the else statement the program will run elif first


#9

Got it, Thank You so much..


#10