This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpirate_bartender.py
60 lines (53 loc) · 2.09 KB
/
pirate_bartender.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#Bartender app. Creating drinks according to customers preferences.
import random
qualities=("strong", "salty", "bitter", "sweet", "fruity")
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 str_to_bol(ans):
ans=ans.lower()
while ans not in ["y", "yes", "n", "no"]:
ans=raw_input("Please enter yes/no. ")
if ans in ["y", "yes"]:
return True
else:
return False
def questions():
users_pref = {}
for quality in qualities:
wanted = raw_input("Do you want your drink %r? (yes/no) " % quality).lower()
users_pref[quality] = str_to_bol(wanted)
return users_pref
def construct_drink (users_pref):
recipe=[]
for quality in users_pref:
if users_pref[quality]:
recipe.append(random.choice(ingredients[quality]))
return recipe
def drink ():
recipe=construct_drink(questions())
print "One drink coming up. It includes:"
for ingrident in recipe:
print " " + ingrident
def main ():
print"Welcome to XXXX bar. I do not want to support over consumption of alcohol. Therefore, I will offer only one drink for a customer. We shall finish working when there are no more customers to serve."
first_iteration = True
while True:
if first_iteration:
deserves_a_drink = raw_input ("Are you a customer? yes/no ")
first_iteration=False
else:
deserves_a_drink = raw_input ("Are you a new customer? yes/no ")
deserves_a_drink = str_to_bol(deserves_a_drink)
if not deserves_a_drink:
break
wants_a_drink = raw_input("Do you want a drink? yes/no ")
wants_a_drink = str_to_bol(wants_a_drink)
if wants_a_drink:
drink()
if __name__ == '__main__':
main()