0% found this document useful (0 votes)
8 views43 pages

Wasifbhaikifile

Python full function With solution

Uploaded by

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

Wasifbhaikifile

Python full function With solution

Uploaded by

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

18. Write Menu Driven code for csv file.

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:

To append data in csv file:


To search data in csv file:

To Update data in csv file:


To count data from csv file:
PROGRAM OF PUSH
OPERATION

CODE:-
def push():
stack=[]
while True:
element=int(input("enter element"))
stack.append(element)
print(stack)
push()CODE:-

PROGRAM OF POP OPERATION

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:-

MENU DRIVEN PROGRAM OF STACKS


CODE:-
def empty(s):
if s==[]:
return True
else:
return False
def pop(s):
if empty(s):
print("empty_ _ _ underflow")
else:
item=s.pop()
if len(s)==0:
top=None
else:
top=len(s)-1
return item
def peek(s):
if empty(s):
return"underflow"
else:
top=len(s)-1
return s[top]
def display(s):
if empty(s):
print("Stack empty")
else:
top=len(s)-1
print(s[top],"<-top")
for a in range(top-1,-1,-1):
print(s[a])
def push(s,e):
s.append(e)
top=len(s)-1
stack=[]
top=None
while True:
print("stack operation")
print("1.Push")
print("2.pop")
print("3.peek")
print("4.Display")
print("5.quit")
ch=int(input("Enter your choice (1-5)"))
if ch==1:
e=int(input("enter the element:"))
push(stack,e)
elif ch==2:
item=pop(stack)
if item=="underflow":
print("underflow!stack is empty")
else:
print("popped item is:",item)
elif ch==3:
item=peek(stack)
if item=="underflow":
print("underflow!!empty stack")
else:
print("topmost item is",item)
elif ch==4:
display(stack)
elif ch==5:
break

CODE:-
To push the data:
To pop the element:

To know the peek element:


To display the elements:
SIMPLE MYSQL QUERIES

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy