FAQ: Control Flow - Relational Operators II


#1

This community-built FAQ covers the “Relational Operators II” exercise from the lesson “Control Flow”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Computer Science
Data Science

FAQs on the exercise Relational Operators II

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head here.

Looking for motivation to keep learning? Join our wider discussions.

Learn more about how to use this guide.

Found a bug? Report it!

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!


#2

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]


#3

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.


#4

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)


#5

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.


#6

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)


#7

That’s not the same code.


#8

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


#9

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


#10

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


#11

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.


#14

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

def graduation_reqs(credits):
if credits >= 120:
return “You have enough credits to graduate”

print(graduation_reqs(120))

it works, but won’t let me continue??


#15

If we use print instead of return why does the word none comes in the console?


#16

so in the 2nd exercise (graduation_reqs function) the default solution is this:
def graduation_reqs(credits):
if credits >= 120:
return “You have enough credits to graduate!”

print(graduation_reqs(120))

So instead of using the print command in order to get the result i wanted to make it more straight by using only the functions name and the input number in it. So i did this and i got error. Can u please explain me why i get error from this?:

def graduation_reqs(credits):
if credits >= 120:
print(“You have enough credits to graduate!”)

graduation_reqs(120)


#17

This is what we would do if our function is expected to return a response.


#18

I dont get it. By creating a function we tell the program that when we type its name everytime its gonna repeat some certain steps in order. So when i type:

def graduation_reqs(credits):
if credits >= 120:
print(“You have enough credits to graduate!”)

graduation_reqs(120)

By evaluating that credits >= 120 as true it should move to the next step which is the print command right?


#19

Indentation is critical in Python. We cannot see yours.


#20

yeah i didnt put ident on the print statement below the if. LoL. code logic was valid though.