Learn
Control Flow
Boolean Operators: not

The final boolean operator we will cover is not. This operator is straightforward: when applied to any boolean expression it reverses the boolean value. So if we have a True statement and apply a not operator we get a False statement.

not True == False not False == True

Consider the following statement:

Oranges are not a fruit.

Here, we took the True statement oranges are a fruit and added a not operator to make the False statement oranges are not a fruit.

This example in English is slightly different from the way it would appear in Python because in Python we add the not operator to the very beginning of the statement. Let’s take a look at some of those:

>>> not 1 + 1 == 2 False >>> not 7 < 0 True

Instructions

1.

Set the variables statement_one and statement_two equal to the results of the following boolean expressions:

Statement one:

not (4 + 5 <= 9)

Statement two:

not (8 * 2) != 20 - 4
2.

The registrar’s office at Calvin Coolidge’s Cool College has been so impressed with your work so far that they have another task for you. They want you to return to the first function you wrote, graduation_reqs, and add in several checks using and and not statements.

  • If a student meets both requirements the function should return
    "You meet the requirements to graduate!"
  • If a student’s GPA is greater or equal to 2.0 but they don’t have enough credits the function should return
    "You do not have enough credits to graduate."
  • If they have enough credits but their GPA is less than 2.0 the function should return
    "Your GPA is not high enough to graduate."
  • If they do not have enough credits and their GPA is less than 2.0, the function should return
    "You do not meet either requirement to graduate!"

Make sure your return value matches those strings exactly. Capitalization, punctuation, and spaces matter!

Folder Icon

Sign up to start coding

Already have an account?