Cover page images (keyboard)

Conditionals & Booleans

Sue Evans & James MacGlashan

Adapted from the CS1 Course at Swarthmore College by Lisa Meeden

Hit the space bar for next slide

Learning Outcomes

Control Structures

If statements and code blocks

If statements take the form :

if <condition>:

Boolean Expressions

If statement execution


Example Program Using if-else



The National Weather Service has 5 categories to describe hurricanes, shown in the following chart:

Category Wind Speed
1 - Minimum 74 - 95 mph
2 - Moderate 96 - 110 mph
3 - Extensive 111 - 130 mph
4 - Extreme 131 - 155 mph
5 - Catastrophic greater than 155 mph

Write Python code that will get the current wind speed from the user and will print out if this is a hurricane and which category number it is.

HINT: Make use of the fact that there are no breaks in the values.
          There is no need to use the and or or operators.

String Conditionals

Boolean Operators

Boolean Algebra

Character Counting Revisited