-
Notifications
You must be signed in to change notification settings - Fork 0
/
bar_guide.py
executable file
·77 lines (56 loc) · 2.4 KB
/
bar_guide.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# Bar Guide
# Bar Guide let's you:
# Display the recipe for a drink
# List all of the drinks in the recipe book
# Add a new drink recipe
# Delete a recipe
# Edit a recipe
# Quit when you're done
__version__ = 1.0
import pickle, shelve
BAR_GUIDE = "bar_guide"
def formatted_input(question):
"""Gets a drink name, recipe or command and returns it properly formatted"""
new_input = input(question)
new_input = new_input.title()
return new_input
# Main
print("Bartender's Guide to Drink Recipies\n")
# Read existing recipes from the Bar Guide book
drink_recipes = shelve.open(BAR_GUIDE, "c")
# Perform requested operations until 'done'
action = None
while action != "Done":
action = formatted_input("Enter <drink name>, 'list', 'add', 'delete', 'edit', or 'done': ")
if action == "List":
print("\n", list(drink_recipes.keys()), "\n")
elif action == "Add":
drink_name = formatted_input("What drink do you want to add? ")
if drink_name in drink_recipes:
print("That drink is already in the recipe book.\n")
else:
drink_recipe = formatted_input("What is the new recipe? ")
drink_recipes[drink_name] = drink_recipe
print(drink_name, "recipe added to the recipe book\n")
elif action == "Delete":
drink_name = formatted_input("What drink do you want to delete from the recipe book? ")
if drink_name in drink_recipes:
del drink_recipes[drink_name]
print(drink_name, "entry deleted\n")
else:
print(drink_name, "not found\n")
elif action == "Edit":
drink_name = formatted_input("What drink do you want to edit in the recipe book? ")
if drink_name in drink_recipes:
new_recipe = formatted_input("What is your new recipe? ")
drink_recipes[drink_name] = new_recipe
print(drink_name, "entry changed to ")
print(drink_recipes.get(drink_name), "\n")
else:
print(drink_name, "not found\n")
elif action == "Done":
drink_recipes.close()
print("Adios, my friend\n")
#Assume that 'action' is a drink name that has been entered
else:
print(drink_recipes.get(action, "I don't know that recipe"), "\n")