Welcome to the Get Help category!
def graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return "You meet the requirements to graduate!"
if (gpa >= 2.0) and not(credits >= 120):
return "You do not have enough credits to graduate."
if not (gpa >= 2.0) and (credits >= 120):
return "Your GPA is not high enough to graduate. "
if not (gpa >= 2.0) and not (credits >=120):
return "You do not meet either requirement to graduate!"
Do you have a little more information? A link to the lesson and the error code would be very useful. Have a check of the following How to ask good questions (and get good answers) for a little detail on how best to set up a question and details of code formatting for the forums.
Without the error it’s hard to say. It looks like a sensible inversion of the initial suite. Have you double checked the content of the sentence itself?
Logic in this style might benefit from a single
if statement followed by
elif clauses as it’s a little more efficient and also makes it clear to the reader that this flow of logic is grouped together.
I’m new, but shouldn’t that be (!gpa) instead of not gpa
not negates the condition
gpa >= 2.0. That means if the
gpa is, for example,
gpa>=2.0 will return
not then negates that to make it
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.