Hacks

  • What do logical operators do?
  • Logical operators help the user connect multiple selections in a selection

Logical operator

Not: displays the opposite of what the data says. And: Checks if both conditions are met. Or: Checks both conditons but only one needs to be met.

isWeekend = False
result = not(isWeekend)
print(result)
True
score = 56

# Has to be between 50 and 100

if score > 50 and score <= 100:
    print("You passed")
You passed
distance = 3
speed = 10
if distance < 2 or speed > 4:
   print("You won!")
Your team won!

Key Terms

  • Selection: The specific block of code that will execute depending on the algorithm condition returning true or false.
  • Algorithm: "A finite set of instructions that accomplish a specific task."
  • Conditional Statement / If-Statement: A statement that affects the sequence of control by executing certain statements depending on the value of a boolean.
x = int(input())

if x % 2 == 0:
      print("thats an even number")
else:
    print("thats an odd number")
thats an odd number
print("are you going to school tommorow?")
reply = input("yes or no")
if reply == "yes":
    print("great")
if reply == "no":
    print("oh no")
are you going to school tommorow?
great
print("what quarter of the year are you in?")
reply = input("1, 2, 3 or 4")
if reply == "1":
    print("Then its January, February or March")
if reply == "2":
    print("Then its April, May or June")
if reply == "3":
    print("Then its June, August or September")
if reply == "4":
    print("Then its October, November or December")
what quarter of the year are you in?
Then its October, November or December