-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpython with csv.py
More file actions
66 lines (65 loc) · 1.93 KB
/
python with csv.py
File metadata and controls
66 lines (65 loc) · 1.93 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
import csv
import os
def write():
f=open("foodvilla.csv","a",newline='')
w=csv.writer(f)
l=["name","age","phone"]
name=input("enter your name")
age=int(input("enter your age"))
people=int(input("enter the number of people with you including children"))
phone=input("enter your phone number")
if len(phone)==10:
pass
else:
print("your number is wrong please check it again")
l=[name,age,people,phone]
w.writerow(l)
f.close()
def display():
f=open("foodvilla.csv","r",newline='')
exm=csv.reader(f)
for i in exm:
print(i)
f.close()
def update():
f1=open("foodvilla1.csv","w")
data1=csv.writer(f1)
f=open("foodvilla.csv","r")
data=csv.reader(f)
r=input("enter your name")
n=input("enter your correct name")
for i in data:
if int(i[0])==r:
data1.writerow(i[0],n,i[2])
else:
data1.writerow(i[0],i[1],i[2])
f.close()
f1.close()
def delete():
lines=list()
members=input("Please enter a member's name to be deleted.")
with open('foodvilla.csv','r',newline='') as readFile:
reader = csv.reader(readFile)
for row in reader:
lines.append(row)
for field in row:
if field == members:
lines.remove(row)
with open('foodvilla.csv', 'w',newline='') as writeFile:
writer = csv.writer(writeFile)
writer.writerows(lines)
readFile.close()
print("your name has been deleted")
while True:
print("MENU \n1=WRITE \n2=DISPLAY \n3=UPDATE \n4=DELETE")
ch=int(input("enter the number"))
if ch==1:
write()
if ch==2:
display()
if ch==3:
update()
if ch==4:
delete()
if ch==5:
print("Thank you, visit us again :D")