Skip to content

Instantly share code, notes, and snippets.

@dmsurti
Created September 21, 2016 12:41
Show Gist options
  • Save dmsurti/e3ad8a6998c958bd69cd5a28d834cd94 to your computer and use it in GitHub Desktop.
Save dmsurti/e3ad8a6998c958bd69cd5a28d834cd94 to your computer and use it in GitHub Desktop.
Bartender initial solution (Gerard)
# 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)
@dmsurti
Copy link
Author

dmsurti commented Sep 21, 2016

Preferences = {}

This dict should be named as preferences. Variable names start with lower case, as a good practice, in Python.

@dmsurti
Copy link
Author

dmsurti commented Sep 21, 2016

    print("{}". format(questions['salty']))
    input ("")
    print("{}". format(questions['bitter']))
    input ("")
    print("{}". format(questions['sweet']))
    input ("")
    print("{}". format(questions['fruity']))
    input ("")

Do you really need to look up each question separately? Can' you loop through the dictionary items and ask the question instead?

Partial code:

for `each question in questions`:
    print(question)

You just need to figure out how to loop through the items in a dictionary.

@dmsurti
Copy link
Author

dmsurti commented Sep 21, 2016

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.

@dmsurti
Copy link
Author

dmsurti commented Sep 21, 2016

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