-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprojectFinal.py
191 lines (146 loc) · 4.35 KB
/
projectFinal.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
"""
Course: CS101
File: projectFinal
Project: 14
Author: Alfredo Pena
Description:
It creates a shopping list according to what the user instructs.
"""
"""
Instructions:
Write a program that allows a user to create and use a shopping list. Your
program will display a menu of options to the user. The user is free
to select any option from the menu in any order.
Sample Output:
Welcome to the shopping list program.
Menu
n - New shopping list item
d - Display shopping list
e - Edit an item in the list
c - Check or remove item from list
? - Display this menu
q - Quit program
> n
Enter shopping item: Bread
> n
Enter shopping item: Milk
> n
Enter shopping item: Eggs
> d
********* Shopping list *********
* 1 Bread *
* 2 Milk *
* 3 Eggs *
*********************************
> e
Which item do you want to change?: 2
Enter your change: Whole Milk
> d
********* Shopping list *********
* 1 Bread *
* 2 Whole Milk *
* 3 Eggs *
*********************************
> e
Which item do you want to change?: 10
Error: There is no item at that position
> e
Which item do you want to change?: 0
Error: There is no item at that position
> ?
Menu
n - New shopping list item
d - Display shopping list
e - Edit an item in the list
c - Check or remove item from list
? - Display this menu
q - Quit program
> c
Which item do you want to check?: 10
Error: There is no item at that position
> c
Which item do you want to check?: 1
Item 1 was checked and removed
> d
********* Shopping list *********
* 1 Whole Milk *
* 2 Eggs *
*********************************
> n
Enter shopping item: Ice Cream
> d
********* Shopping list *********
* 1 Whole Milk *
* 2 Eggs *
* 3 Ice Cream *
*********************************
> q
Good bye
"""
# TODO - add your project code here
############################# FUNCTIONS ###############################
def displayMenu():
print("Menu")
print(" n - New shopping list item")
print(" d - Display shopping list")
print(" e - Edit an item in the list")
print(" c - Check or remove item from list")
print(" ? - Display this menu")
print(" q - Quit program")
def welcomeMsg():
print("Welcome to the shopping list program.")
print()
def instruction():
letter = input("> ")
return letter
def newItem():
item = input("Enter shopping item: ")
return item
def correctItem():
correction = shoppingList[int(input("Which item do you want to change?: "))]
if correction in shoppingList:
x = shoppingList.index(correction)
correctedItem = input("Enter your change: ")
shoppingList[x] = correctedItem
def checkItem():
x = input("Which item do you want to check?: ")
itemChecked = shoppingList[int(x)]
if itemChecked in shoppingList:
shoppingList.remove(itemChecked)
print("Item",x,"was checked and removed")
def displayList():
print('{:*^30}'.format(' Shopping List '))
for item in shoppingList:
print('* {: <27}*'.format(str(shoppingList.index(item))+ " " + item))
print ("{:*<30}".format ("*"))
def errorMsg():
print("Error: There is no item at that position")
################################# MAIN CODE ###################################
welcomeMsg()
displayMenu()
shoppingList = []
selectedOption = 1
while selectedOption != "q":
selectedOption = instruction()
if selectedOption == "n":
item = newItem()
shoppingList.append(item)
if selectedOption == "d":
displayList()
if selectedOption == "e":
try:
correctItem()
except IndexError:
errorMsg()
if selectedOption == "c":
try:
checkItem()
except IndexError:
errorMsg()
if selectedOption == "?":
displayMenu()
if selectedOption == "q":
print("Good bye")
"""
Happy Spring break! :-D
"""