Python: Match Statement
Posted: Tue Jul 22, 2025 1:51 pm
Code: Select all
try:
vowel = input("Pick a vowel.:")
except ValueError:
return "Pick another datattype. It must be a string."
else:
match vowel:
case "a":
print("You picked a, a vowel.")
case "e":
print("You picked e, a vowel.")
case "i":
print("You picked i, a vowel.")
case "o":
print("You picked o, a vowel")
case "u":
print("You picked u, a vowel.")
case_:
print("You didn't pick a vowel.")
#--------------------------------
# User inputs some string into the vowel variable.
# The code states that the variable vowel is being matched.
# If the string matches up with one of the cases, then the user is informed of their choice.
# If the string isn't a string that is exactly a letter and a vowel, then the case_ will match up and inform the user that he/she didn't pick a vowel.