Introduce the newish match conditional
This commit is contained in:
parent
6c4e660819
commit
efaa3b3c57
23
Python/026_matchcase.py
Normal file
23
Python/026_matchcase.py
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
# Case, switch, match example
|
||||||
|
# Note: Python's match implementation was introduced in Python version 3.10
|
||||||
|
|
||||||
|
num = None
|
||||||
|
while num is None:
|
||||||
|
try:
|
||||||
|
num = int(input("Enter a number between 1 and 3: "))
|
||||||
|
except:
|
||||||
|
print(" Oops, that's not a number...")
|
||||||
|
|
||||||
|
match num:
|
||||||
|
# match 1
|
||||||
|
case 1:
|
||||||
|
print("You entered One")
|
||||||
|
# match 2
|
||||||
|
case 2:
|
||||||
|
print("You entered Two")
|
||||||
|
# match 3
|
||||||
|
case 3:
|
||||||
|
print("You entered Three")
|
||||||
|
# match default (i.e. no match)
|
||||||
|
case _:
|
||||||
|
print("You did not follow directions!")
|
Loading…
Reference in New Issue
Block a user