-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpartyplanner.py
290 lines (234 loc) · 8.47 KB
/
partyplanner.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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
import csv
import sys
#Author: Ramon Stanly Rodriguez
"""
Party planner the final project of the CPT-168 class
the purpose of this program is to receive data from a user
such as attendee name, attendee type can be member guest or student
and the food of their choice, after receive all the data entered by the user
this program will save all that information into a csv file named partyplanner.csv
that is going to be used by the program to retrieve any of the data whenever is need it
"""
CSVFILE = "partyplanner.csv"
#write the entries to a csv file
def WriteTocsv(ln):
try:
with open(CSVFILE, "a", newline="") as Wfile:
write = csv.writer(Wfile)
write.writerows(ln)
except PermissionError as err:
print("Permission error, the file might be open, please close the file", err)
print()
#reads entries of the csv file and returns the data
def ReadCsv():
try:
data = []
with open(CSVFILE, newline="") as rfile:
reader = csv.reader(rfile)
for row in reader:
data.append(row)
return data
except FileNotFoundError as err:
print(f"Error can not find the file\n{err}")
print()
sys.exit()
#count and display the total amount of food choices
def foodCounter():
csvDataFile = ReadCsv()
chicken = 0
beef = 0
sushi = 0
vegetarian = 0
pizza = 0
for row in csvDataFile:
if row[2] == "chicken":
chicken += 1
elif row[2] == "beef":
beef += 1
elif row[2] == "vegetarian":
vegetarian += 1
elif row[2] == "sushi":
sushi += 1
elif row[2] == "pizza":
pizza += 1
print(f"Total orders of chicken:\t{chicken}")
print(f"Total orders of beef:\t\t{beef}")
print(f"Total orders of sushi:\t\t{sushi}")
print(f"Total orders of vegetarian:\t{vegetarian}")
print(f"Total orders of pizza:\t\t{pizza}")
print()
#count number of members guests and students
def TotalMembersGuestsStudents(message, mg):
csvDataFile = ReadCsv()
count = 0
for n, eachPerson in enumerate(csvDataFile, start=1):
if eachPerson[1] == mg:
count += 1
print(message, count)
#show each member from the csv file
def ListMembers():
csvDataFile = ReadCsv()
for eachMember in csvDataFile:
if eachMember[1] == "Member":
print(f"{eachMember[0]:<10} {eachMember[1]:<10} {eachMember[2]:<10} {'$':>5}{eachMember[3]:>1}")
print()
#show each guest from the csv file
def ListGuests():
csvDataFile = ReadCsv()
for eachGuest in csvDataFile:
if eachGuest[1] == "Guest":
print(f"{eachGuest[0]:<10} {eachGuest[1]:<10} {eachGuest[2]:<10} {'$':>2}{eachGuest[3]:>1}")
print()
#show each student from the csv file
def ListStudents():
csvDataFile = ReadCsv()
for eachStudent in csvDataFile:
if eachStudent[1] == "Student":
print(f"{eachStudent[0]:<10} {eachStudent[1]:<10} {eachStudent[2]:<10} {'$':>5}{eachStudent[3]:>1}")
print()
#show each members, guests and students with the food choices and fee
def ListMembersGuestsStudents():
csvDataFile = ReadCsv()
if len(csvDataFile) == 0:
print("The csv file is empty please add some values.\n")
print()
else:
for i, mg in enumerate(csvDataFile, start=1):
print(f"{i:<5} {mg[0]:<10} {mg[1]:<10} {mg[2]:<10} {'$':>4}{mg[3]:>1}")
print()
print()
#count and display the total fees
def TotalFees():
fees = [] #empty list
csvDataFile = ReadCsv()
for eachFee in csvDataFile:
if eachFee[3] != 0:
fees.append(eachFee[3])
#converts each item in the fees list in integer
for e in range(0, len(fees)):
fees[e] = int(fees[e]) #converts each item in the fees list to integer
feesTotal = sum(fees) #adds each item in the fees list and returns the total
print(f"Total Fees Paid by all attendees: ${feesTotal}")
print()
#show all the commands
def Commands():
print()
print("COMMAND MENU")
print("add => Add members, guests or students")
print("lm => List all members")
print("lg => List all guests")
print("ls => List all students")
print("lmgs => List all members, guests and students")
print("cmd => Display the list of commands")
print("rp => Display a full report")
print("exit => Exit the program")
print()
"""
show report function
show a full report with the members, guests and students with the name and the food choice
this function can also show the total numbers of members guests and students
can also show the total fees and the total of food choice
"""
def Report():
ListMembersGuestsStudents()
TotalMembersGuestsStudents("Total Members:\t","Member")
TotalMembersGuestsStudents("Total Guests:\t", "Guest")
TotalMembersGuestsStudents("Total Students:\t","Student")
TotalFees()
foodCounter()
"""
prompts the user
to enter a food choice from the food menu
and returns the food chosen by the user
"""
def MenuChoices():
foodMenu = {"c": "chicken", "b": "beef", "v": "vegetarian", "s": "sushi", "p": "pizza"}
validation = True
while(validation):
print("If you want chicken type 'c'")
print("for beef type 'b'")
print("for vegetarian type 'v'")
print("for sushi type 's'")
print("for pizza type 'p'")
food = input("Enter Your Menu Choice: ")
foodL = food.lower()
print()
if(foodL in foodMenu):
return foodMenu[foodL]
else:
print("Invalid Input, Pleae Try Again.")
print()
validation = True
#prompts the user to enter the attendee name, member, guest or student then save the information in a csv file
def AddMembersGuestsStudents():
m = "Member"
g = "Guest"
s = "Student"
price = 21 #regular fee for members and guests
studentFee = 10 #fee for students
members = [] #empty list that only holds members
guests = [] #empty list that only holds guests
students = [] #empty list that only holds students
GuestMemberOrStudent = [] #empty list that can hold members guests or students
name = input("Enter attendee name: ")
print()
validation = True
while(validation):
print("For member enter letter 'm'")
print("For guest enter letter 'g'")
print("For student enter letter 's'")
MGS = input("Enter attendee type: ")
print()
if(MGS.lower() == "m"):
food = MenuChoices()
GuestMemberOrStudent = [name, m, food, price]
members.append(GuestMemberOrStudent)
WriteTocsv(members)
print(members[0][0], members[0][1], members[0][2], "was added.")
validation = False
elif(MGS.lower() == "g"):
food = MenuChoices()
GuestMemberOrStudent = [name, g, food, price]
guests.append(GuestMemberOrStudent)
WriteTocsv(guests)
print(guests[0][0], guests[0][1], guests[0][2], "was added.")
validation = False
elif(MGS.lower() == "s"):
food = MenuChoices()
GuestMemberOrStudent = [name, s, food, studentFee]
students.append(GuestMemberOrStudent)
WriteTocsv(students)
print(students[0][0], students[0][1], students[0][2], "was added.")
validation = False
else:
print("Invalid Input, Please Try Again")
print()
validation = True
#main function
def main():
print("Welcome To The Party Manager Program")
Commands()
while(True):
command = input("Command: ")
print()
if(command.lower() == "add"):
AddMembersGuestsStudents()
elif(command.lower() == "lm"):
ListMembers()
elif(command.lower() == "lg"):
ListGuests()
elif(command.lower() == "ls"):
ListStudents()
elif(command.lower() == "lmgs"):
ListMembersGuestsStudents()
elif(command.lower() == "cmd"):
Commands()
elif(command.lower() == "rp"):
Report()
elif(command.lower() == "exit"):
break
else:
print("Invalid command, please try again or type 'cmd' to display the list of commands")
print()
if __name__ == "__main__":
main()