Now that we’ve added conditional statements to our toolkit for building control flow, let’s explore more ways to create boolean expressions. So far we know two relational operators, equals and not equals, but there are a ton (well, four) more:
Let’s say we’re running a movie streaming platform and we want to write a function that checks if our users are over 13 when showing them a PG-13 movie. We could write something like:
def age_check(age): if age >= 13: return True
This function will take the users age and compare it to the number 13. If
age is greater than or equal to 13 it will return
Let’s try some more!
Write a function called
greater_than that takes two integer inputs,
y and returns the value that is greater. If
y are equal, return the string
"These numbers are the same"
The nearby college, Calvin Coolidge’s Cool College (or 4C, as the locals call it) requires students to earn 120 credits to graduate. Write a function called
graduation_reqs that takes an input
credits and checks if the student has enough credits to graduate. If they do, return the string
"You have enough credits to graduate!"
graduation_reqs with an input of 120
credits and print the result to the terminal. Can a student with 120
credits graduate from Calvin Coolidge’s Cool College?