Skip to content

Instantly share code, notes, and snippets.

@dmsurti
Created September 26, 2016 06:29
Show Gist options
  • Save dmsurti/25cda12c1372c389f96e09c9c5894d75 to your computer and use it in GitHub Desktop.
Save dmsurti/25cda12c1372c389f96e09c9c5894d75 to your computer and use it in GitHub Desktop.
Bartender (Submission by Hans)
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"],
}
def ask():
answers = {}
for key in questions.keys():
answers[key] = input(questions[key] + " ")
return answers
def tend(answers):
print('\n\nHere we go:\n')
for key in answers.keys():
if answers[key] != "":
if answers[key].lower()[0] == 'y':
print(random.choice(ingredients[key]))
print('\n\n')
if __name__ == '__main__':
answers = ask()
tend(answers)
@dmsurti
Copy link
Author

dmsurti commented Sep 26, 2016

    for key in questions.keys():
        answers[key] = input(questions[key] + " ")

It would be preferable to store the answers[key] as a Boolean. That will simplify when you pick the random ingredient in tend.

Further, the instruction asks to store the answer as a Boolean.

@dmsurti
Copy link
Author

dmsurti commented Sep 26, 2016

     if answers[key] != "":
            if answers[key].lower()[0] == 'y':

This is better implemented as if answers[key]:, see my previous comment.

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