FAQ: Control Flow - Relational Operators II

Yes dude!!! I’m also getting this same error…message :frowning:

@discobot display help
Please do solve the web page error.

Hi! To find out what I can do, say @discobot display help.

In order to graduate, a student must have at least 120 credits.

What would happen if we called graduation_reqs(120)?

Side note: discobot cannot resolve this type of inquiry.

1 Like

No kidding. What purpose would any of us serve if that were the case? Luckily we’re only helping new STEM pursuers to reach that level of ML and AI, or at least some degree of solution analysis by the bot. The SCT would be relegated, mind.


Can I get some feedback on my control flow function, I want to know if there is anyway to rewrite this in 2 if statements instead of 3.


def greater_than(x, y):
  if x == y:
    return "These numbers are the same"
  elif x > y:
    return x
  elif y > x:
    return y

Since there are only three possibilities, then one of them can be the default, thereby eliminating one of the elifs.

    if x > y: return x
    if y > x: return y
    return "These numbers are the same".    #  default

Since each branch returns to the caller, we don’t even need an elif

Extra Study (to keep under your hat for the time being)

return x if x > y else y if y > x else "These numbers are the same"

The above is a conditional expression, rather than an if statement. Only one outcome can be returned.


ahh thank you so much I was on this for like 30 minutes trying to think of how can I make it more efficient code. thank you big time!

1 Like

You’re welcome. I would advise at this time to focus less on efficiency and more on the practical value of naive code. Write what works, first, then examine it for possible ways to simplify it. It’s not about efficiency, but diversification. Build a library in your mind of the many and varied ways to perform the same action or arrive at the same outcome. That’s the real beauty of any language, Python no less.


ok definitely ill keep that in mind

1 Like