-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathshopping_list.py
More file actions
78 lines (55 loc) · 1.35 KB
/
shopping_list.py
File metadata and controls
78 lines (55 loc) · 1.35 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
import os
import random
shopping_list = ["apples"]
def clear():
if os.name == 'nt':
os.system('cls')
else:
os.system('clear')
def show_help():
clear()
print("What should we pick up at the store? ")
print("""
ENTER 'DONE' to stop adding items.
ENTER 'HELP' for this help.
ENTER 'SHOW' to see your current list.
""")
def add_to_list(item):
show_list()
if len(shopping_list):
position = input("Where should I add {}?\n"
"Press ENTER to add to the end of the list\n"
"> ".format(item))
else:
position = 0
try:
position = abs(int(position))
except ValueError:
position = None
if position is not None:
shopping_list.insert(position - 1, item)
else:
shopping_list.append(new_item)
show_list()
def show_list():
clear()
print("Here's your list:")
index = 1
for item in shopping_list:
print("{}. {}".format(index, item))
index += 1
print("-" * 10)
help()
while True:
new_item = input("> ")
if new_item.upper() == 'DONE' or new_item.upper() == 'QUIT':
break
elif new_item == 'HELP':
show_help()
continue
elif new_item == 'SHOW':
show_list()
continue
else:
add_to_list(new_item)
show_list()