Wasifbhaikifile
Wasifbhaikifile
CODE:-
L=[]
count=1
import csv
def writecsv():
global count
f=open("Student.csv","w",newline="")
stuw=csv.writer(f)
stuw.writerow(["Roll no","Name","Marks"])
while True:
print("Student record",count)
R=int(input("Enter roll no of student"))
N=input("Enter student name")
M=int(input("Enter student marks"))
sturec=[R,N,M]
stuw.writerow(sturec)
count=count+1
ch=input("Want to add more data (y/n)")
if ch in "Nn":
break
f.close()
def readcsv():
f=open("Student.csv","r",newline="")
stur=csv.reader(f)
for i in stur:
print(i)
f.close()
def appendcsv():
global count
f=open("Student.csv","a",newline="")
stuw=csv.writer(f)
while True:
print("Student record",count)
R=int(input("Enter roll no of student"))
N=input("Enter student name")
M=int(input("Enter student marks"))
sturec=[R,N,M]
stuw.writerow(sturec)
count=count+1
ch=input("Want to add more data (y/n)")
if ch in "Nn":
break
f.close()
def searchcsv():
f=open("Student.csv","r",newline="")
stur=csv.reader(f)
found=False
cho=input("Enter student roll no whose data to be searched")
for i in stur:
if i[0]==cho:
print(i)
found=True
break
if found==True:
print("Data founded successfully")
else:
print("no such data founded")
f.close()
def updatecsv():
f=open("Student.csv","r",newline="")
cr=csv.reader(f)
found=0
nrec=[]
cho=input("Enter student roll no whose data to be updated")
for i in cr:
if i[0]==cho:
print("Current record",i)
i[1]=input("Enter new name")
print("Updated record",i)
found=1
nrec.append(i)
if found==0:
print("Sorry! no record founded... ")
f.close()
else:
f=open("Student.csv","w",newline="")
w=csv.writer(f)
w.writerows(nrec)
f.close()
def countcsv():
f=open("Student.csv","r",newline="")
cw=csv.reader(f)
count=0
for i in cw:
count+=1
print("Total no. of records=",count)
f.close()
while True:
print("-"*50)
print("1: To write")
print("2: To Read")
print("3: To append")
print("4: To search")
print("5: To update")
print("6: To count")
ch=int(input("Enter your choice between 1-6"))
if ch==1:
writecsv()
elif ch==2:
readcsv()
elif ch==3:
appendcsv()
elif ch==4:
searchcsv()
elif ch==5:
updatecsv()
elif ch==6:
countcsv()
Output:-
To add data in csv file:
To read data from csv file:
CODE:-
def push():
stack=[]
while True:
element=int(input("enter element"))
stack.append(element)
print(stack)
push()CODE:-
CODE:-
def POP(st):
if st==[]:
print ("stack is empty underflow else:")
else:
print ("deleted element is:",st.pop())
stack=[1,2,3,4]
POP(stack)
CODE:-
CODE:-
To push the data:
To pop the element: