Having confusion with Control Flow topic

Hello everyone!
I keep running my code and it works, yet codecademy is saying it is incorrect. I don’t really understand what is going on. I don’t want to be for bad habits when writing code so that I why I am asking the community for a little clearification. My code is as follows- ef graduation_reqs(gpa, credits):
if (gpa >= 2.0) and (credits >= 120):
return “You meet the requirements to graduate!”
elif (gpa >= 2.0) and not (credits >= 120):
return “You do not have enough credits to graduate.”
elif (credits >= 120) and not (gpa <= 2.0):
return “Your GPA is not high enough to graduate.”
elif (credits <= 120) and not (gpa >= 2.0):
return “Your GPA is not high enough to graduate.”
else:
(credits != 120) and (gpa != 2.0)
return “You do not meet either requirement to graduate!”

print(graduation_reqs(0.0,0))
It works in the python shell when I run it, but I want to know what I am doing wrong and why my question is wrong.

1 Like

Hey there and welcome to the forums!! :slightly_smiling_face:

In the future please look at formatting your code, as this preserves indentation, which is an important part of Python, and makes it easier to copy/paste code into an editor.

To format code, simply press this button:

Than copy/paste your code between the two rows of backticks:


Do you have a link to this lesson? Seeing the exact requirements could be helpful, as quiet often a lesson will be picky about small details like how a string is typed.

A couple things I see that look “off” are your second elif:

elif (credits >= 120) and not (gpa <= 2.0):

Is the less than or equal to operator, <=, what you meant to use here?

Second in your else, there is not reason to supply a condition, as the else covers all other circumstances.

2 Likes

Thank you!!! I really do appreciate the help!!!

3 Likes