Skip to content

Instantly share code, notes, and snippets.

@barraponto
Forked from j10sanders/piratebartender.py
Last active October 6, 2015 13:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save barraponto/e8e879814e0c677fd1c5 to your computer and use it in GitHub Desktop.
Save barraponto/e8e879814e0c677fd1c5 to your computer and use it in GitHub Desktop.
__author__ = 'Jonathan'
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"]
}
adjectives = ["Poopy", "Nasty", "Hairy", "Shiny", "Dapper"]
nouns = ["Person", "Flower", "Clothing", "Necktie"]
def parse_pirate_answer(answer):
'''Make sense out of pirate talk. @TODO: support ARRRR'''
# straight pirate talk
answer = answer.strip().lower()
if answer.startswith('yes'):
return True
elif answer.startswith('no'):
return False
# not a clear yes or no, maybe already drunk.
assume = None
print('Ye talking gibberish, mate!')
if answer.startswith('y'):
assume = True
elif answer.startswith('n'):
assume = False
# no idea, just do as we please.
if assume is None:
assume = random.choice([True, False])
return assume
def pirate_preferences():
'''Be nice and almost respect the pirate customer.'''
preferences = []
for preference, question in questions.items():
if parse_pirate_answer(input(question)):
preferences.append(preference)
return preferences
def pirate_drink(preferences):
drink = []
for preference in preferences:
drink.append(random.choice(ingredients[preference]))
return drink
def pirate_drinkname():
return random.choice(adjectives) + " " + random.choice(nouns)
def bartending(count=0):
if count == 0:
question = "Would ye like me to make you a drink? (Yes or No) "
else:
question = "Would ye like me to make another drink? (Yes or No) "
return parse_pirate_answer(input(question))
def main():
counter = 0
preferences = pirate_preferences()
while bartending(counter):
print("Here's a {drink} made with {ingredients}.".format(
drink=pirate_drinkname(),
ingredients=', '.join(pirate_drink(preferences))))
counter = counter + 1
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment