CSV
CSV
def create():
with open('std.csv','w', newline='') as f:
w = csv.writer(f)
a = 'y'
while a.lower()=='y':
stuId = int(input('enter the id: '))
name = input('enter name: ')
s1 = int(input('enter subject 1 mark: '))
s2 = int(input('enter subject 2 mark: '))
s3 = int(input('enter subject 3 mark: '))
s4 = int(input('enter subject 4 mark: '))
s5 = int(input('enter subject 5 mark: '))
msum = s1+s2+s3+s4+s5
avg=msum/5
l=[stuId, name, msum, avg]
w.writerow(l)
a = input('do you want to add more records:(yes,no) ')
def display():
with open('std.csv','r') as f:
r = csv.reader(f)
print('id' ,'name', 'Sum of all the marks','avg. marks',
sep='\t')
for i in r:
print(i[0], i[1], i[2], i[3], sep='\t')
def search(sid):
with open('std.csv','r') as f:
r = csv.reader(f)
for i in r:
if int(i[0])==sid:
print('Total marks of',i[1],'is',i[-2])
print('avrage marks of',i[1],'is',i[-1])
ans="y"
while ans.lower()=="y":
print("1.Create A CSV File")
print("2.Display The Content File")
print("3.Search Based On StudentID")
choice=int(input("Enter your choice:"))
if choice==1:
create()
if choice==2:
display()
if choice==3:
sid=int(input('enter student Id: '))
search(sid)