computer science practical file class 12
computer science practical file class 12
SOURCE CODE:
SOURCE CODE:--
def
isempt(stack)
: if
stack==[]:
return
True else:
return False
def
push(stack,item
):
stack.append(ite
m)
top=len(stack)
+1
def
pop(stack,item
): if
isempt(stack):
return
"underflow" else:
top=len(stack)
==0 return
item
def peek(stack):
if isempt(stack):
return
"underflow" else:
top=len(stack)
+1 return
stack[top]
def
display(stack)
: if
isempt(stack)
:
print("stack is empty")
else:
top=len(stack)-1
print(stack[top])
for i in range(top-1,-1,-
1): print(stack[i])
# main
stck=[]
top=None
while True:
print("stack operations")
print("1,push")
print("2.pop")
print("3,peek"
)
print("4,display
")
print("5,exit")
ch=int(input("enter your choice(1-
5):")) if ch==1:
itm=int(input("enter an
item:")) push(stck,itm)
elif ch==2:
item=pop(stck,i
tm)
if item == "underflow":
print("underflow!! stack is
empty")
else:
print("popped item
is:",item) elif ch==3:
item=peek(stck)
if item=="underflow":
print("underflow! stack is
empty")
else:
print("topmost item
is:",item) elif ch==4:
display(stck)
elif ch==5:
brea
k else:
print("invalid choice!")
#OUTPUT OF PROGRAM 12:-
PROGRAM#19: - Write a program in python that fetches all the recordsfrom
the stud table of your database.
SOURCE CODE:-
SOURCE CODE: -
mycon=sqltor.connect(host="localhost",user="root",password="surya",d
atabase
="ajay")
if mycon.is_connected()==False:
print("Error connecting to mysql
databse") cursor=mycon.cursor()
for s in
data:
print(s)
mycon.close()
#OUTPUT OF PROGRAM 20: -