Skip to content

Instantly share code, notes, and snippets.

@dmsurti
Created September 23, 2016 04:16
Show Gist options
  • Save dmsurti/c50d1f89b584c6ca293ef69ca77931b9 to your computer and use it in GitHub Desktop.
Save dmsurti/c50d1f89b584c6ca293ef69ca77931b9 to your computer and use it in GitHub Desktop.
Pirate bartender solution review (for Ryan)
import random
questions = {
"strong": "Do ye like yer drinks strong?",
"salty": "Do ye like it with a salty tang?",
"bitter": "Are ye a lubber who likes it bitter?",
"sweet": "Would ye like a bit of sweetness with yer poison?",
"fruity": "Are ye one for a fruity finish?",
}
ingredients = {
"strong": ["glug of rum", "slug of whisky", "splash of gin"],
"salty": ["olive on a stick", "salt-dusted rim", "rasher of bacon"],
"bitter": ["shake of bitters", "splash of tonic", "twist of lemon peel"],
"sweet": ["sugar cube", "spoonful of honey", "spash of cola"],
"fruity": ["slice of orange", "dash of cassis", "cherry on top"],
}
#Create new dictionary
order = {}
def drink_order():
"""
Ask each of the questions in the questions dictionary.
Gather the responses in a new dictionary.
"""
#Create For loop to fill in k,y which is mapped to boolean value"""
for k,v in questions.items():
print v #Prints question
response = raw_input().lower()
if response == "y" or response == "yes":
order[k] = True
else:
order[k] = False
return order
def drink_constructor(order):
"""
Take preferences from "order" dictionary as parameter
Append corresponding ingredient
"""
#List inside function
menu = []
for k,v in order.items():
if v:
menu.append(random.choice(ingredients[k]))
return menu
if __name__ == '__main__':
drink_order()
print(drink_constructor(order))
@dmsurti
Copy link
Author

dmsurti commented Sep 23, 2016

With the above change, you need to pass the order returned by drink_order as such:

order = drink_order()

@dmsurti
Copy link
Author

dmsurti commented Sep 23, 2016

  • drink_order is better renamed as take_drink_order or order_drink
  • drink_constructor is better renamed as make_drink_menu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment