Elif Conditional statement

Okay! So I just covered the [elif] conditional statement and it seemed pretty simple. So I wanted to try to apply the [elif] to previous exercises and be a little extra for practice!

However, when I applied [elif] to [and] and [or] statements, it only printed the first [if] instead of checking other statements? Any tips on what I might have done wrong or can do to improve this practice?

credits = 190
gpa = 2.5

if gpa >= 2.0 or credits >= 120:
  print("La De Dah, You met a requirement to graduate, Kid!")
elif gpa >= 2.0 and credits >= 120:
  print ("Holy Crap you met both requirements to graduate!")
  print("Wow you gotta do better dood")

All that prints in the above code is the first [if] when it should print the [elif] statement.

I think you should re-visit what Boolean operators or and and do.

Considering the given values that you’ve assigned to credits and gpa… one of the conditions is met, or True, with the if statement. So, the print() statement is executed.

When you use the operator and both conditions have to be met. But more importantly, the elif won’t run b/c one condition in the if is already met.

For practice, I would suggest changing the gpa and credits values in the variables or the conditional statements to see what happens.



This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.