Why doesn't my code work without a print?

why can’t I run the code if the (if) condition is satisfied? It only runs when you add a print statement while calling the function. Why is it happening ? [exercise of relational operataors II ][https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-control-flow/lessons/control-flow/exercises/relational-operators-ii]

2 Likes

We need to see your code to be able to answer this question. Please post it in a reply. Thank you for posting the URL of the exercise. That makes things so much easier now that we know where to test what you have.

sir, here is the code of that particular thing.

def graduation_reqs(gpa, credits):
if (gpa >=2.0) and (credits >=120):
return “You meet the requirements to graduate!”
if (gpa >= 2.0 ) and (credits < 120):
return “You do not have enough credits to graduate.”
if (gpa <2.0) and (credits >=120):
return “Your GPA is not high enough to graduate.”
if (gpa < 2.0) and (credits < 120):
return “You do not meet either requirement to graduate!”

graduation_reqs(0.0,0)

There is no output from the above code. The value is returned to the caller and everything ends there. To see the return value we must print it, or at least assign it to a variable so it can be retrieved and printed later.

2 Likes

Then why is it not printing this :-
def applicant_selector(gpa, ps_score, ec_count):
if gpa >= 3.0 and ps_score >= 90 and ec_count >= 3:
return “This applicant should be accepted.”
elif gpa >= 3.0 and ps_score >= 90 and ec_count < 3:
return “This applicant should be given an in-person interview.”
else:
return “This applicant should be rejected.”
a = applicant_selector(4.0,92,3)
print(a)

That’s not the same code.

1 Like

This code is for the following problem on the website
https://www.codecademy.com/paths/computer-science/tracks/cspath-flow-data-iteration/modules/dspath-control-flow/lessons/control-flow/exercises/review

This is off-topic. Can we solve the original, on topic problem and step away?

1 Like

Yes sir we can solve the original one . I will try to grasp it from there itself.

If you have a problem still with that other lesson, stay engaged here. We will see that it gets archived in the appropriate section, while we work out a solution with you.

2 Likes

This exercise is a bit weird, If I follow step 2 to the “t”, and do not print (it does not ask for a print, just to define the function) I can’t move on… In step 1 it does not require a print. I let it solve it for me and it showed me the exact same info I entered.