Professional Documents
Culture Documents
CODE:
glassStack = list()
def isEmpty(glassStack):
if len(glassStack)==0:
return True
else:
return False
def opPush(glassStack,element):
glassStack.append(element)
def top(glassStack):
if isEmpty(glassStack):
print('Stack is empty')
return None
else:
x =len(glassStack)
element=glassStack[x-1]
return element
ans='Y'
print('Pushing element',element)
opPush(glassStack,element)
OUTPUT:
Q2) Write a menu driven program to perform the following operations on a Stack for the book details
(bookNo, bookName) using function:
a. Push operation
b. Pop operation
c. Peek opertion
CODE:
s=[]
while (True):
if (choice==1):
s.append(a)
elif (choice==2):
if (s==[]):
else:
elif (choice==3):
elif (choice==4):
if (s==[]):
continue
l=len(s)
print('Values in Stack..\n')
for i in range(l-1,-1,-1):
print (s[i])
else:
print('Wrong Input')
OUTPUT:
Q3) BCCI has created a dictionary containing top players and their runs as key value pairs of cricket team.
Write a program, with separate user defined functions to perform the following operations:
● Push the keys (name of the players) of the dictionary into a stack, where the corresponding value (runs) is
greater than 49.
For example:
The output from the program should be: SACHIN SAURAV YUVRAJ
CODE:
SCORE={'KAPIL':40,'SACHIN':55,'SAURAV':80,'RAHUL':35,'YUVRAJ':110}
def push(s,n):
s.append(n)
def pop(s):
if s!=[]:
return s.pop()
else:
return none
st=[]
for k in SCORE:
if SCORE[k]>=49:
push(st,k)
while True:
if st!=[]:
print(pop(st),end=' ')
else:
break
OUTPUT:
Q4) Write a Python code to connect a MySQL database namely SHOP and use the following table Stationery
and Consumer and send SQL commands to the database and retrieve the records based on the queries given
below:
(iii) To display the ConsumerName, Address from Table Consumer, and Company and Price from table
Stationery, with their corresponding matching S_ID.
(iv) Display the maximum and minimum price for each company.
Using Python MySQL Connector, execute the following SQL commands on the above
iv. GROUP BY and find the min, max, sum, count and average mark
Creating Table:-
Inserting Data:-
i)
ii)
iii)
iv)
v)