Assignment: If…Elif…Else Conditions⌗

In this assignment, you will use if...elif...else statements to create two interactive drawings. Press different keys to change the appearance of each drawing.

Quick Recall⌗

If Statement⌗

An if statement runs code only when a condition is True.

if condition:
    # Runs when condition is True

If…Else Statement⌗

An if...else statement chooses between two actions.

if condition:
    # Runs when condition is True
else:
    # Runs when condition is False

If…Elif…Else Statement⌗

An if...elif...else statement checks multiple conditions and executes the first matching block.

if condition1:
    # First action
elif condition2:
    # Second action
else:
    # Default action

Starter Template⌗

Use this template for both parts of the assignment.

from animation import run_sketch

def draw(p, key):

    # Draw the sketch here


run_sketch(draw, bgcolor="lightblue")

Part 1 - Thermometer⌗

Create an interactive thermometer that displays different temperature levels.

Thermometer showing different temperature levels

Instructions:

  • Press C to show a cold temperature (blue).
  • Press W to show a warm temperature (yellow).
  • Press H to show a hot temperature (red).
  • Change the height and color of the temperature level based on the key pressed.
  • Use if...elif...else to select the temperature.

Part 2 - Mood Indicator⌗

Create an interactive mood indicator that displays three different facial expressions.

Mood indicator showing happy, neutral, and sad faces

Instructions:

  • Press S to show a sad face (purple).
  • Press N to show a neutral face (gold).
  • Press H to show a happy face (pink).
  • Change the face color and mouth expression based on the key pressed.
  • Use if...elif...else to select the mood.

Submission⌗

Submit both Python files to Google Classroom:

  • Part 1 - Thermometer
  • Part 2 - Mood Indicator

Make sure both programs run correctly before submitting.