Professional Documents
Culture Documents
2021-2022
CLASS :12TH
EAST DELHI PUBLIC SCHOOL
______________ ______________
Signature of Signature of
Teacher. External
INDEX
1 : Write a program, with separate user defined functions to perform the following operations:
● Push the keys (name of the student) of the dictionary into a stack, where the corresponding value
s.append(n) push(ST,i)
if s!=[]: print(pop(ST),end=‘ ‘)
else: break
return None
2 : Write a program with separate user defined functions to perform the following operations
● Traverse the content of the list and push the even numbersinto a stack.
For Example:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
38 22 98 56 34 12
PROGRAM
: OUTPUT
# Stack Implementation
# Main program
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
ST=[]
# Function Push()
for i in N:
def push(s,n):
if i%2==0:
s.append(n)
push(ST,i)
# Function pop()
while True:
def pop(s):
if ST!=[]:
if s!=[]:
print(pop(ST),end=‘ ‘)
return s.pop()
else:
else:
break
return None
3:Write a program to implement a stack for the employee details (empno,
name). PROGRAM:
stk=[] top=-1 def
Def display(): def main(): while
line():
global stk True: line()
print('~'*100) def global top
isEmpty(): global print("1. Push")
if top==-1:
stk if stk==[]: print("2. Pop")
isEmpty()
print("Stack is else: print("3.
empty!!!") else: top=len(stk)-1 Display")
None def push(): print(stk[top],”<- print("4. Exit")
global stk global top”) ch=int(input("Ent
for i in er your choice:"))
top
range(top-1,-1,-1): if ch==1:nm
empno=int(input( print(stk[i])
"Enter the push()
employee number print("Element
def pop_ele():
to push:")) global stk Pushed") elif
ename=input("En global top ch==2: pop_ele()
ter the employee if top==-1: elif ch==3:
name to push:") isEmpty() display() else:
else: print("Invalid
stk.append([empn stk.pop()
o,ename]) Choice")
top=top-1
top=len(stk)-1
OUTPUT:
Part B: 5 sets of SQL queries using one/two tables
Queries Set 1 (Database Fetching records)
[1] Consider the following MOVIE table and write the SQL queries based on it.
1-Display all information from movie.
2-Display the type of movies.
3-Display movieid, moviename, total_eraning by showing the business done by the movies. Claculate the business
done by movie using the sum of productioncost and businesscost.
4-Display movieid, moviename and productioncost for all movies with productioncost greater thatn 150000 and less
than 1000000.
5-Display the movie of type action and romance.
6-Display the list of movies which are going to release in February, 2022.
Answers:
OUTPUT:
2. Select distinct from a movie;
PROGRAM:
import mysql.connector as conn
mydb=conn.connect(host="localhost",user="root",passwd="tiger",database="csfile")
# create new cursor
cur=mydb.cursor()
eno=int(input("Enter Employee number : "))
sl=float(input('Enter Salary : '))
sql="update emp set sal=%f where empno=%d" % (sl,eno)
try:
ans=input("Are you sure you want to update the record : ")
if ans=='y' or ans=='Y':
cur.execute(sql)
print("Emp no-",eno," salary updated successfully...")
mydb.commit()
except Exception as e:
print("Error! Perhaps Emp no is incorrect...",e)
mydb.rollback()
mydb.close()
OUTPUT:
2: Write a Program to show how to DELETE a record from a database table Emp
using
mydb=conn.connect(host=“localhost”,user=“root”,passwd=“tiger”,database=“csfile”)
cur=mydb.cursor()
if ans==‘y’ or ans==‘Y’:
OUTPUT:
cur.execute(sql)
mydb.commit()
except Exception as e:
mydb.rollback()
mydb.close()