Overview

Frequently you want a program to do one thing in one situation and a different thing some other time. The programming structure that allows for this is a conditional. Today will be focused on the conditional structures in Python and the necessary Boolean values.

Basic Learning Objectives

Before class, you should be able to:

  • Define what Boolean values are
  • Recognize the if/elif/else syntax for conditionals
  • Define what the and, or, and not logical operators do
  • Define what the in operator does in the basic case

Advanced Learning Objectives

After class, you should be able to:

  • Use basic, nested, and chained conditionals to solve a problem
  • Use logical operators to solve a problem
  • Predict what code will do when short-circuit boolean evaluation is used

Resources

You should read/watch the following:

Checks

Submit answers to the following on Moodle.

  • (Checkpoint 5.9.2) What will the following code print?
x = 3
y = 5
z = 2

if x < y and x < z:
  print("a")
elif y < x and y < z:
  print("b")
else:
  print("c")
  • Write a snippet of code that prints out whether the value in the variable mystery is greater than or less than 5.