Professional Documents
Culture Documents
Class 12 Practical - Answer
Class 12 Practical - Answer
PYTHON PROGRAMS
1.Write a program using user defined function CheckPrime(N) that takes a number N as parameter and
display the prime numbers from 2 to N
def PRIME(N): o/p
print("Prime numbers from 2 to ", N, "are") Enter the number =10
for i in range(2, N+1): Prime numbers from 2 to 10 are
for j in range(2, i): 2
if i%j == 0: 3
break 5
else: 7
print(i)
num = int(input("Enter the number ="))
PRIME(num)
2. Write a program using user defined function to read a text file and display the number of vowels ,
consonants, uppercase and lowercase characters in it.
def COUNT( ): o/p
F = open("Test1.txt", "r") The content of the file is
str = F.read( ) COMPUTER SC
print("The content of the file is") File Handling
print(str) Text Files
V =C= UC=LC=0
for i in str: No of Vowels : 10
if i.isalpha(): No of Consonants are : 21
if i.islower( ): No of Lower case letters : 17
LC +=1 No of Upper case letters : 14
elif i.isupper( ):
UC += 1
if i in 'aeiouAEIOU':
V += 1
else:
C += 1
print("No of Vowels :", V)
print("No of Consonants are :" , C)
print("No of Lower case letters :", LC)
print("No of Upper case letters :", UC)
F.close()
def WRITE():
F = open("Test1.txt","w")
L=['COMPUTER SC\n', 'File Handling \n', 'Text Files\n']
F.writelines(L)
F.close()
WRITE()
COUNT()
3.Write a program using user defined function to create a binary file with rollno and name. Search for a
given rollno and display the name, if not found display appropriate message.
import pickle o/p
def WRITE( ): WRITING RECORDS......
print("\n\nWRITING RECORDS......" ) Enter roll no:101
F=open("Bfile.dat","wb") Enter name: RAJ
while True: Do you want to enter more
rno=int(input("Enter roll no:")) records?(y/n)y
name =input("Enter name: ") Enter roll no:102
data= [rno , name] Enter name: RAVI
pickle.dump(data, F) Do you want to enter more
ch = input("Do you want to enter more records?(y/n)") records?(y/n)y
if ch in 'nN': Enter roll no:103
break Enter name: MOHAN
F.close( ) Do you want to enter more
records?(y/n)y
def SEARCH( ): Enter roll no:104
print("\n\nSEARCHING A RECORD....." ) Enter name: JACK
F=open("Bfile.dat","rb") Do you want to enter more
rno = int(input("Enter roll no:")) records?(y/n)n
found =0
try:
while True: SEARCHING A RECORD.....
S = pickle.load(F) Enter roll no:103
if S[0] == rno: RECORD FOUND……
print("RECORD FOUND……") NAME = MOHAN
print("NAME =", S[1])
found = 1
except EOFError:
F.close()
if found == 0:
print("Record not found….")
WRITE()
SEARCH()
4. Write a program using user defined function to create a CSV file by entering userid and password.
Display the password for given userid .
import csv o/p
def WRITE(): Enter user id:RAJ12
F= open("User.csv","w",newline="") Enter password:R101
W=csv.writer(F) Do you want to enter more records ?(y/n)y
W.writerow(["USERID", "PASSWORD"]) Enter user id:RAVI12
while True: Enter password:R105
uid=input("Enter user id") Do you want to enter more records ?(y/n)y
pword=input("Enter password") Enter user id:MOHAN12
data=[uid, pword] Enter password:M221
W.writerow(data) Do you want to enter more records ?(y/n)y
ch = input("Do you want to enter more records ?(y/n)") Enter user id:HARI12
if ch in "nN": Enter password:H431
break Do you want to enter more records ?(y/n)n
F.close( ) Enter user id to search: MOHAN12
PASSWORD= M221
def SEARCH( ):
F =open("User.csv", "r")
found = 0
uid= input("Enter user id to search")
R = csv.reader(F)
next(R)
for i in R:
if i[0] == uid:
print("PASSWORD=",i[1])
found = 1
if found == 0:
print("No record found")
F.close()
WRITE()
SEARCH()
o/p
1.PUSH 2.POP 3.Display elements of stack
Enter your choice1
Enter the element which you want to push10
Do you want to continue or not(y/n) ?y
1.PUSH 2.POP 3.Display elements of stack
Enter your choice1
Enter the element which you want to push20
Do you want to continue or not(y/n) ?y
1.PUSH 2.POP 3.Display elements of stack
Enter your choice1
Enter the element which you want to push30
Do you want to continue or not(y/n) ?y
1.PUSH 2.POP 3.Display elements of stack
Enter your choice3
The elements in the stack = [10, 20, 30]
Do you want to continue or not(y/n) ?y
1.PUSH 2.POP 3.Display elements of stack
Enter your choice2
Deleted element is : 30
Do you want to continue or not(y/n) ?y
1.PUSH 2.POP 3.Display elements of stack
Enter your choice3
The elements in the stack = [10, 20]
Do you want to continue or not(y/n) ?n
DATABASE MANAGEMENT
1)Write the sql queries for the following questions:
i)Create the following table Student:
i)Display students’ information , who are paying fees between 2500 and 3500
ii)Remove adno 444 information.
iii)Increase the fees value by 100 for adno 222
iv)Display lowest and highest fees.
Ans)
i)SELECT * FROM Student WHERE Fees BETWEEN 2500 AND 3500;
ii)DELETE FROM Student WHERE Adno = 444;
iii)UPDATE Student SET Fees = Fees + 100 WHERE Adno =222;
iv)SELECT MIN(Fees) , MAX(Fees) FROM Student;
Ans)
i)SELECT INAME, PRICE, BNAME
FROM ITEM I , BRAND B
WHERE I.ICODE = B.ICODE AND PRICE BETWEEN 25000 AND 30000;
ii)SELECT ICODE , PRICE , BNAME
FROM ITEM I , BRAND B
WHERE I.ICODE = B.ICODE AND INAME = “Television”;
iii)UPDATE ITEM SET PRICE = PRICE + PRICE *0.1 ;