Created
September 21, 2016 12:41
-
-
Save dmsurti/e3ad8a6998c958bd69cd5a28d834cd94 to your computer and use it in GitHub Desktop.
Bartender initial solution (Gerard)
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
# yes = True | |
# y = True | |
# no = False | |
# n = False | |
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?", | |
} | |
Preferences = {} | |
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"], | |
} | |
def Bartender (yes,y,no,n): | |
"""You tell me what you like, I make it!""" | |
print("I'm a function. My name is {}".format(Bartender.__name__)) | |
print("I'm a bit slow, I only accept yes or no answers") | |
print("{}". format(questions['strong'])) | |
input("answer") | |
if "answer" == True: | |
Preferences['strong'] = 1 | |
print("{}". format(questions['salty'])) | |
input ("") | |
print("{}". format(questions['bitter'])) | |
input ("") | |
print("{}". format(questions['sweet'])) | |
input ("") | |
print("{}". format(questions['fruity'])) | |
input ("") | |
if __name__ == '__main__': | |
Bartender (yes,y,no,n) |
def Bartender (yes,y,no,n)
Again it is not idiomatic Python to start variable, function, class, method names etc to start with upper case.
def bartender(yes, y, no, n
is much better.
if "answer" == True:
Preferences['strong'] = 1
- Won't the user enter yes, y, no, n for an answer, IIRC. Then you should be comparing answering with that.
- Also, you can store Booleans in a dictionary. So that makes it evident that
preferences['strong'] = 1
has a simpler solution.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do you really need to look up each question separately? Can' you loop through the dictionary items and ask the question instead?
Partial code:
You just need to figure out how to loop through the items in a dictionary.