Created
September 25, 2018 13:52
-
-
Save juzten/f20e4cd069e9bdb911d81f25cef38e9d to your computer and use it in GitHub Desktop.
Python Switch statement
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def print_greeting(venue, name): | |
"""Print greeting for a specific venue.""" | |
venues = { | |
'walmart': walmart_greeting, | |
'target': target_greeting, | |
'aldi': aldi_greeting, | |
'food lion': food_lion_greeting, | |
} | |
return venues.get(venue)(name) if venue in venues else None | |
def walmart_greeting(name): | |
print(f'Welcome to walmart {name}, the lowest prices in town!') | |
def target_greeting(name): | |
print(f'Hi {name}, we have 5% off today at Target') | |
def aldi_greeting(name): | |
print(f'{name}, welcome back to Aldi, did you forget something?') | |
def food_lion_greeting(name): | |
print(f'Welcome to Food Lion {name}, care for a free sample?) | |
print_greeting('walmart', 'Juzten') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Another version of switch