Created
September 23, 2016 04:16
-
-
Save dmsurti/c50d1f89b584c6ca293ef69ca77931b9 to your computer and use it in GitHub Desktop.
Pirate bartender solution review (for Ryan)
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
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)) | |
With the above change, you need to pass the order
returned by drink_order
as such:
order = drink_order()
drink_order
is better renamed astake_drink_order
ororder_drink
drink_constructor
is better renamed asmake_drink_menu
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This need not be a module scope variable. You are already returning the order from
drink_order
, so it is better to keeporder
as a local variable indrink_order
and delete the module scope variable.