Class XII Practical File 2023-24
Class XII Practical File 2023-24
________________ ________________
Signature of Internal Examiner Signature of External Examiner
INDEX
S.no Practical Date Signature
def push():
stack.append(a)
return a
def pop():
if stack==[]:
print('stack underflow')
else:
def display():
if stack==[]:
print('stack is empty!')
else:
for i in range(len(stack)-1,-1,-1):
print(stack[i])
stack=[]
print('STACK OPERATIONS')
choice='y'
while choice=='y':
print('1.PUSH')
print('2.POP')
print('3.DISPLAY')
if c==1:
push()
elif c==2:
pop()
elif c==3:
display()
else:
print('wrong input')
OUTPUT:
Q2.Write a menu driven program to push book no in stack and popit from stack.
#Write a menu driven program to push book no in stack and pop it from stack
stk=[]
ch='Y'
while(ch=='Y' or ch=='y'):
print('enter 1: push')
print('enter 2: pop')
stk.append(d)
print('item appended')
elif opt==2:
if (stk==[]):
print('stack empty')
else:
p=stk.pop()
print('deleted element:',p)
else:
print('invalid choice')
ch=(input('want to continue?'))
OUTPUT:
Q3. Read a text file and display the no. of vowels, consonant , upper case
, lower case and character
def cnt():
f=open("test2.txt","r")
cont=f.read()
print(cnt)
v=0
cons=0
l_c_l=0
u_c_l=0
for ch in cont:
if (ch.islower()):
l_c_l+=1
elif(ch.isupper()):
u_c_l+=1
ch=ch.lower()
if( ch in ['a','e','i','o','u']):
v+=1
'h','j','k','l','m',
'n','p','q','r','s',
't','v','w','x','y','z']):
cons+=1
f.close()
#main program
cnt()
OUTPUT:
Q4. Create a Binary file with name, roll no search for a given roll no and display the
name if not found print inappropriate message.
import pickle
import sys
dict={}
def write_in_file():
file=open("D:\\stud2.dat","ab") #a-append,b-binary
no=int(input("ENTER NO OF STUDENTS: "))
for i in range(no):
print("Enter details of student ", i+1)
dict["roll"]=int(input("Enter roll number: "))
dict["name"]=input("enter the name: ")
pickle.dump(dict,file) #dump-to write in student file
file.close()
def display():
#read from file and display
file=open("D:\\stud2.dat","rb") #r-read,b-binary
try:
while True:
stud=pickle.load(file) #write to the file
print(stud)
except EOFError:
pass
file.close()
def search():
file=open("D:\\stud2.dat","rb") #r-read,b-binary
r=int(input("enter the rollno to search: "))
found=0
try:
while True:
data=pickle.load(file) #read from file
if data["roll"]==r:
print("The rollno =",r," record found")
print(data)
found=1
break
except EOFError:
pass
if found==0:
print("The rollno =",r," record is not found")
file.close()
#main program
while True:
print("MENU \n 1-Write in a file \n 2-display ")
print(" 3-search\n 4-exit \n")
ch=int(input("Enter your choice = "))
if ch==1:
write_in_file()
if ch==2:
display()
if ch==3:
search()
if ch==4:
print(" Thank you ")
sys.exit()
OUTPUT:
Q5. Create a binary file with roll no , name and marks input the roll no and update
the marks.
import pickle
#creating the file and writing the data
f=open("records.dat", "wb")
#list index 0 = roll number
#list index 1 = name
#list index 2 = marks
pickle.dump([1, "harshit", 90], f)
pickle.dump([2, "Tanish", 80], f)
pickle.dump([3, "Priyashi", 90], f)
pickle.dump([4, "rudra", 80], f)
pickle.dump([5, "Ashutosh", 85], f)
f.close()
OUTPUT:
Q6. Remove all the lines that contain “a” in a file and write into another file.
fo=open("hp.txt","w")
fo.write("Harry Potter")
fo.close()
fo=open('hp.txt','r')
fi=open('writehp.txt','w')
l=fo.readlines()
for i in l:
if 'a' in i:
i=i.replace('a','')
fi.write(i)
fi.close()
fo.close()
Output:
Q7. Write a random number generator that generates random number between 1 and
6 (rolling of dice).
import random
min = 1
max = 6
roll_again = "y"
OUTPUT:
Q8. Write a query to display “put” from the word “computer”.
OUTPUT:
Query-select concat(day(now()),concat(‘.’,month(now()),concat(‘.’,year
(now()))))”date”;
OUTPUT-
Q10. Write a query to display ‘DIA’ from the word ‘MEDIA’.
OUTPUT:
Q11. Create a database sport and create a table team with two columns TEAMID &
TEAMNAME.
⮚ USE SPORTS;
⮚ CREATE TABLE TEAM(TEAMID INT(1),TEAMNAME VARCHAR(10),PRIMARY
KEY(TEAMID));
⮚ INSERT INTO TEAM VALUE(1,'TEHLKA');
⮚ SELECT*FROM TEAM;
OUTPUT-
12. Create another table Match Details.
⮚ DESC MATCH_DETAILS;
OUTPUT-
Q13. Based on the above two tables Team and Match_details answer the following
question.
1)display the matched,teamid,teamscore who scored more than 70 in first inning
along with team name.
⮚ select
match_details.matchid,match_details.firstteamid,team.teamname,match_de
tails.firstteamscore from match_details,team where
match_details.firstteamid=team.teamid and
match_details.firstteamscore>70;
OUTPUT-
2)Display matched,teamname and secondteamscore between 100 to 160.
OUTPUT-
4)Display unique team names.
OUTPUT-
OUTPUT-
Q14.From the table movies given below answer the following questions.
OUTPUT-
OUTPUT-
2)display maximum price of itmes for each dealer individually as per decode from
stock.
OUTPUT-
4)Display average price of items for each dealer individually as per dcode from
orderby where average price is more than 5.
OUTPUT-
5)Display the sum of quantity for each dcode.
OUTPUT-
⮚ import mysql.connector
⮚ con=mysql.connector.connect(host='localhost',user='root',password='may12
3@@',databse='sports')
⮚ cursor=con.cursor()
⮚ cursor.execute(a)
⮚ con.commit()
⮚ con.close()
OUTPUT-
import mysql.connector
def show_databases():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123")
mycursor=mydb.cursor()
mycursor.execute("SHOW DATABASES")
for x in mycursor:
print(x)
def show_tables():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("SHOW TABLES")
for x in mycursor:
print(x)
def create_table():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("create table customers(name varchar(255),address
varchar(255))")
def insert_value():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
a="insert into customers value('sneha','117-D,noida');"
mycursor.execute(a)
mydb.commit()
print(mycursor.rowcount,"record inserted.")
def display_value():
mydb=mysql.connector.connect(host="localhost",user="root",password="sn
eha@123",database="sports")
mycursor=mydb.cursor()
mycursor.execute("select * from customers")
myresult=mycursor.fetchall()
for x in myresult:
print(x)
#MAIN PROGRAM
while True:
print('''-----------
MENU
-----------''')
print(" List of choice")
print("1.")
print("2.")
print("3.")
print("4.")
print("5.")
ch=int(input("choose the function you want to perform"))
if ch==1:
show_databases()
elif ch==2:
show_tables()
elif ch==3:
create_table()
elif ch==4:
insert_value()
elif ch==5:
display_value()
else:
print("wrong option selected")
OUTPUT: