-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShopping_List_App3.py
More file actions
102 lines (72 loc) · 2.11 KB
/
Copy pathShopping_List_App3.py
File metadata and controls
102 lines (72 loc) · 2.11 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import os
# make a list to hold the shopping list items
shopping_list_items = []
def clear_screen():
# enable this if the script is ran on the terminal
#os.system("cls" if os.name == "nt" else "clear")
print("\n"*100)
def show_help():
clear_screen()
# print out instructions on how to use the app
print("What shall we get from the store?")
print("""
Type DONE to quit the app
Type HELP to show instructions
Type SHOW to show shopping list
""")
def show_items():
clear_screen()
show_help()
print("Here is your list: ")
# print out the whole list
for index, item in enumerate(shopping_list_items, start=1):
print("{}. {}".format(index, item))
print("-"*10)
def remove_from_list():
show_items()
what_to_remove = input("What would you like to remove?\n> ")
try:
shopping_list_items.remove(what_to_remove)
except ValueError:
pass
show_items()
def add_item(new_item):
show_items()
if len(shopping_list_items):
position = input("Where do you want to put {} \n"
"Press Enter to add it to the end of the list \n"
"> ".format(new_item)
)
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list_items.insert(position-1, new_item)
else:
# add new items to our list
shopping_list_items.append(new_item)
show_help()
while True:
# ask for new items
new_item = input("> ")
# how type DONE to quit the app
if new_item.upper() == 'DONE' or new_item.upper() == 'QUIT':
break
elif new_item.upper() == 'HELP':
show_help()
continue
elif new_item.upper() == 'SHOW':
show_items()
continue
elif new_item.upper() == 'REMOVE':
remove_from_list()
elif new_item == "":
print("Cannot add an empty item to the list, please enter a valid item")
continue
else:
# adds new items
add_item(new_item)
show_items()