-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshopping_list_4.py
54 lines (48 loc) · 1.58 KB
/
shopping_list_4.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
shopping_list = []
def remove_item(idx):
index = idx - 1
item = shopping_list.pop(index)
print("Remove {}.".format(item))
def show_help():
print("\nSeparate each item with a comma.")
print("Type DONE to quit, SHOW to see the current list, "
"REMOVE to delete an item, and HELP to get this message")
def show_list():
count = 1
for item in shopping_list:
print("{}: {}".format(count, item))
count += 1
print("Give me a list of things you want to shop for.")
show_help()
while True:
new_stuff = input("> ")
if new_stuff == "DONE":
print("\nHere's your list: ")
show_list()
break
elif new_stuff == "HELP":
show_help()
continue
elif new_stuff == "SHOW":
show_list()
continue
elif new_stuff == "REMOVE":
show_list()
idx = input("Which item? Tell me the number. ")
remove_item(int(idx))
continue
else:
new_list = new_stuff.split(",")
index = input("Add this at a certain spot? Press enter for the end of the list, "
"or give me a number. Currently {} items in the list.\n".format(len(shopping_list)))
if index:
try:
spot = int(index) - 1
for item in new_list:
shopping_list.insert(spot, item.strip())
spot += 1
except ValueError:
print("{} is not a number. Please enter your item again.".format(index))
else:
for item in new_list:
shopping_list.append(item.strip())