cs programs part3
cs programs part3
import csv
with open('Student_Details.csv','w',newline='') as csvf:
writecsv=csv.writer(csvf,delimiter=',')
choice='y'
while choice.lower()=='y':
rl=int(input("Enter Roll No.: "))
n=input("Enter Name: ")
p=float(input("Enter Percentage: "))
r=input("Enter Remarks: ")
writecsv.writerow([rl,n,p,r])
print(" Data saved in Student Details file..")
choice=input("Want add more record(y/n) ")
with open('Student_Details.csv',newline='') as fileobject:
readcsv=csv.reader(fileobject)
for i in readcsv:
print(i)
OUTPUT
# Write a python program to implement a stack using a list data-structure.
def push(stk,item):
stk.append(item)
top=len(stk)-1
def pop(stk):
if stk==[]:
return "underflow"
else: item=stk.pop()
if len(stk)==0:
top=None
else:
top=len(stk)-1
return item
def peek(stk):
if stk==[]:
return "underflow"
else:
top=len(stk)-1
return stk[top]
def display(stk):
if stk==[]:
print('stack is empty')
else:
top=len(stk)-1
print(stk[top],'<-top')
for i in range(top-1,-1,-1):
print(stk[i])
#Driver Code
def main():
stk=[]
top=None
while True:
print("stack operation \n1.push \n2.pop \n3.peek \n4.display \n5.exit")
choice=int (input('enter choice:'))
if choice==1:
item=int(input('enter item:'))
push(stk,item)
elif choice==2:
item=pop(stk)
if item=="underflow":
print('stack is underflow')
else: print('poped')
elif choice==3:
item=peek(stk)
if item=="underflow":
print('stack is underflow')
else:
print('top most item is:',item)
elif choice==4:
display(stk)
elif choice==5:
break
else:
print('invalid')
exit()
main()
OUTPUT