0% found this document useful (0 votes)
19 views3 pages

Cuti Set

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

Cuti Set

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

import csv

def add():
f = open("vehicle.csv", "a", newline="")
w = csv.writer(f)
reg = input("enter your reg: ")
name = input("enter your name: ")
offence = input("enter your offence: ")
if offence == "d&d":
fine = 10000
elif offence == "mobile":
fine = 4000
elif offence == "seat belt":
fine = 2000
elif offence == "overspeed":
fine = 5000
else:
fine = 3000

l = [reg, name, offence, fine]


w.writerow(l)
f.close()

def display():
f = open("vehicle.csv", "r")
r = csv.reader(f)
for i in r:
print("name:", i[1], "fine:", i[3], "\n", "offence:", i[2], "\n")
f.close()

def search():
reg = input("enter for search: ")
f = open("vehicle.csv", "r")
r = csv.reader(f)
flag = -1
for i in r:
if i[0].upper() == reg.upper():
print(i[0], i[2])
flag = 1
break
if flag == -1:
print("No data for", reg)
f.close()

def modify():
reg_no = input("enter reg no for search: ")
f = open("vehicle.csv", "r")
r = csv.reader(f)
flag = -1
new_data = []
for i in r:
if i[0].upper() == reg_no.upper():
name = input("enter name: ")
offence = input("enter offence: ")
offence = offence.upper()

if offence == "D&D":
fine = 10000
elif offence == "MOBILE":
fine = 4000
elif offence == "SEAT BELT":

1
fine = 2000
elif offence == "OVERSPEED":
fine = 5000
else:
fine = 3000

l = [reg_no, name, offence, fine]


new_data.append(l)
flag = 1
else:
new_data.append(i)
f.close()
if flag == -1:
print("no data for", reg_no) # Fixed string syntax
else:
f = open("vehicle.csv", "w", newline="")
w = csv.writer(f)
w.writerows(new_data)
f.close()

def remove():
name = input("enter name to remove: ")
f = open("vehicle.csv", "r")
r = csv.reader(f)
flag = -1
new_data = []
for i in r:
if i[1].upper() != name.upper():
new_data.append(i)
else:
flag = 1

f.close()
if flag == -1:
print("no data for", name)
else:
f = open("vehicle.csv", "w", newline="")
w = csv.writer(f)
w.writerows(new_data)
f.close()

def summary():
d = {}
f = open("vehicle.csv", "r")
r = csv.reader(f)
for i in r:
if i[2] not in d:
d[i[2]] = int(i[3])
else:
d[i[2]] += int(i[3])
f.close()
for a in d:
print(a, d[a])

ch = '1'
while ch != '6':
print("menu\n1.add\n2.display\n3.search\n4.modify\n5.remove\n6.summary") # Changed '5' to '6
ch = input("enter your choice: ")
if ch == '1':
add()
elif ch == '2':

2
display()
elif ch == '3':
search()
elif ch == '4':
modify()
elif ch == '5':
remove()
elif ch == '6':
summary()

You might also like