# elif for value rangesdefclassify_temp(t):
if t < 0:
return"freezing"elif t < 20:
return"cold"elif t < 30:
return"warm"else:
return"hot"# match for structural patternsdefprocess_command(cmd):
match cmd.split():
case ["quit"]:
return"Quitting"case ["go", direction]:
returnf"Going {direction}"case ["pick", "up", item]:
returnf"Picking up {item}"case _:
returnf"Unknown: {cmd}"print(classify_temp(25))
print(process_command("go north"))
print(process_command("pick up sword"))
Output
Click "Run" to execute your code
Use elif for simple value/range checks. Use match/case for destructuring complex data structures.
Challenge
Try modifying the code above to explore different behaviors. Can you extend the example to handle a new use case?