# COMMON MATCH / CASE MISTAKES
# Each block shows the wrong way, the error it produces, and the right way
# Read through — don't just run it top to bottom

# ─────────────────────────────────────────────
# MISTAKE 1 — Using match on Python 3.9 or earlier
# ─────────────────────────────────────────────

# Wrong — SyntaxError on Python 3.9 or earlier
# match command:
#     case "quit":
#         print("Quitting.")

# Check your version first
import sys
print(sys.version)

# match / case requires Python 3.10 or later

# ─────────────────────────────────────────────
# MISTAKE 2 — Forgetting case _
# ─────────────────────────────────────────────

command = "start"

# Wrong — no fallback, unknown values silently ignored
match command:
    case "quit":
        print("Quitting.")
    case "help":
        print("Help.")
# "start" — nothing happens, no error

# Right — always handle the unexpected
match command:
    case "quit":
        print("Quitting.")
    case "help":
        print("Help.")
    case _:
        print("Unknown command.")

# ─────────────────────────────────────────────
# MISTAKE 3 — Case sensitive matching
# ─────────────────────────────────────────────

command = "Quit"    # user typed with capital Q

# Wrong — doesn't match "quit"
match command:
    case "quit":
        print("Quitting.")
    case _:
        print("Unknown command.")    # runs instead

# Right — normalize before matching
match command.lower():
    case "quit":
        print("Quitting.")
    case _:
        print("Unknown command.")

# ─────────────────────────────────────────────
# MISTAKE 4 — case _ in the wrong place
# ─────────────────────────────────────────────

# Wrong — case _ first, nothing else runs
# match command:
#     case _:
#         print("Unknown.")
#     case "quit":          # never reached
#         print("Quitting.")

# Right — case _ always last
match command:
    case "quit":
        print("Quitting.")
    case _:
        print("Unknown.")

# ─────────────────────────────────────────────
# MISTAKE 5 — Using match when if / elif is clearer
# ─────────────────────────────────────────────

score = 85
attendance = 90

# Awkward — match forced on unrelated conditions
# match score:
#     case n if n > 90 and attendance > 80:
#         print("Honours.")

# Better — if / elif is clearer here
if score > 90 and attendance > 80:
    print("Honours.")
elif score > 60:
    print("Passed.")

# ─────────────────────────────────────────────
# Quick reference
# ─────────────────────────────────────────────

# match requires Python 3.10+
# always add case _ — unmatched values silently ignored
# normalize with .lower() before matching strings
# case _ always goes last — matches everything
# match for one variable — if/elif for complex logic
