# ============================================================
# LESSON 2 — Conditional Execution
# Based on: Python for Everybody (PY4E) by Dr. Chuck Severance
# Video: https://www.youtube.com/watch?v=8DvywoWv6fI (1:26:00 – 1:52:48)
#
# Read the theory on the lesson page first, then work
# through each section here and run the world to see output.
# ============================================================
# ============================================================
# SECTION 1 — Boolean Expressions
# ============================================================
print(5 == 5) # True
print(5 != 3) # True
print(3 < 5) # True
print(5 > 3) # True
print(3 <= 3) # True
print(4 >= 5) # False
# TASK: Change the values above and predict what each line will print
# before you run it.
# ============================================================
# SECTION 2 — The if Statement
# ============================================================
x = 10
if x > 5:
print("x is greater than 5")
print("this always runs")
# TASK: Change x to 3 and run the world again. Notice which line is skipped.
# ============================================================
# SECTION 3 — if / else
# ============================================================
age = 16
if age >= 18:
print("You can vote.")
else:
print("You are too young to vote.")
# TASK: Change age to 18, then to 21. Run after each change.
# ============================================================
# SECTION 4 — if / elif / else
# ============================================================
score = 72
if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C")
elif score >= 60:
print("Grade: D")
else:
print("Grade: F")
# TASK: Change score to 85, then 55, then 90. Run after each change.
# ============================================================
# SECTION 5 — Logical Operators
# ============================================================
age = 20
has_id = True
if age >= 18 and has_id:
print("Entry allowed.")
else:
print("Entry refused.")
# TASK: Set has_id to False and run again.
# Then change the 'and' to 'or' — what is different?
# ============================================================
# SECTION 6 — try / except
# ============================================================
raw = await input("Enter a number: ")
try:
number = int(raw)
print("You entered:", number)
except:
print("That was not a valid number.")
# TASK: Run the world twice — once typing a number, once typing a word.
# Notice how try/except stops the program from crashing.
# ============================================================
# SECTION 7 — Exercise
# ============================================================
# Write a program that:
# 1. Asks the user to enter a temperature in Celsius
# 2. Uses try/except to catch invalid input
# 3. If the input is valid, print one of these messages:
# Below 0 -> "Freezing"
# 0 to 15 -> "Cold"
# 16 to 25 -> "Mild"
# 26 to 35 -> "Warm"
# Above 35 -> "Hot"
#
# Expected output (if the user types 22):
# Mild
# Write your solution here: