Professional Documents
Culture Documents
CLASS-XII SC
TERM-2
Code No. 083
2021-22
----------------------------------------------------------------------------------------------------
PROGRAMS FOR REPORT FILE (PRACTICAL RECORD)
1. Write a program that depending upon user’s choice either push or pop an element
in a stack.
def Push_Stack(STACK,item):
STACK.append(item)
top=len(STACK)-1
def Stack_Pop(STACK):
if STACK==[]:
return "underflow"
else:
item=STACK.pop()
if len(STACK)==0:
top=None
else:
top=len(STACK)-1
return item
def Stack_Display(STACK):
if STACK==[]:
return "underflow"
else:
top=len(STACK)
#print(STACK[top]," ")
for a in range(0,top,1):
print(STACK[a])
STACK=[]
top=None
while True :
print("[1] Push")
print("[2] Pop")
def Push_Book(BOOK,bname):
BOOK.append(bname)
top=len(BOOK)-1
def Pop_Book(BOOK):
if BOOK==[]:
return "underflow"
else:
bname=BOOK.pop()
if len(BOOK)==0:
top=None
else:
top=len(BOOK)-1
return bname
def Display_Book(BOOK):
if BOOK==[]:
return "underflow"
else:
top=len(BOOK)
for a in range(0,top,1):
BOOK=[]
top=None
while True :
print("[1] Push Book Name on Library")
print("[2] Pop Book Name from Library")
print("[3] Dsiplay Book Name")
print("[4] Exit")
ch=int(input("Enter your choice 1 to 4 "))
if ch==1:
bname=input("Enter your Book name ")
Push_Book(BOOK,bname)
elifch==2:
bname=Pop_Book(BOOK)
if bname=="underflow":
print("Book Library is Empty")
else:
print("popped Book is ",bname)
elifch==3:
Display_Book(BOOK)
else :
break
3. A line of text is read from the input terminal into a stack. Write an program to
output the
string in the reverse order, each character appearing twice.
(e.g a b c d e should be changed to ee dd cc bb aa).
def Push_Char(LOC,cname):
LOC.append(cname)
top=len(LOC)-1
def Display_Char(LOC):
if LOC==[]:
return "underflow"
else:
top=len(LOC)
for a in range(top-1,-1,-1):
print(LOC[a]*2," ")
Consider the following tables FACULTY and COURSES. Write the MySQL queries from
(i) to (v).
FACULTY
F_ID Fname Lname Join_date Salary
102 Amit Mishra 12-10-1998 12000
103 Nitin Vyas 24-12-1994 8000
104 Rakshit Soni 18-5-2001 14000
105 Rashmi Malhotra 11-9-2004 11000
106 Sulekha Srivastava 5-6-2006 10000
COU
RSE
S
C_ID F_ID Cname Fees
C21 102 GridComputing 40000
C22 106 SystemDesign 16000
C23 104 ComputerSecurity 8000
C24 106 ComputerSecurity 15000
C25 102 SystemDesign 20000
C26 107 VisualBasic 6000
CODES
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="STUDENTDB"
)
db_cursor = db_connection.cursor()
ST=UPDATE STUDENT SET price = price+(price*0.1) WHERE name LIKE "Su%"
OR "Sh%"; #Updating records
db_cursor.execute(ST)
db_connection.close()
CODE
import mysql.connector
db_connection = mysql.connector.connect(
host="localhost",
user="root",
passwd="root",
database="SCHOOLDB"
)
db_cursor = db_connection.cursor()
ST=SELECT Name, Department, MAX(Salary) FROM TEACHER WHERE
SEX="F"; #Updating records
db_cursor.execute(ST)
db_connection.close()
---------------