Final Practical
Final Practical
PRACTICAL FILE
FOR
THE FULLFILLMENT OF SSCE 2023-24 EXAMINATION
return 0
else:
return list[size - 1] + sumOfList(list, size - 1)
total = sumOfList(list1, len(list1))
print("Sum of all elements in given list: ", total)
Practical -4
Write a program to calculate the nth term of Fabonacci
series
i=int(input("enter number "))
x=0
y=1
z=1
print("Fabonacci series")
print(x,y,end="")
while(z <= i):
print(z)
x=y
y=z
z=X+y
Practical 5
data = file.readlines()
for i in data:
print(i.replace(' ',"#"))
Practical 13
Program to read the content of a file and display the total
no.Of consonants,vowels,lowercase & uppercase characters.
def count():
f=open("article.txt","r")
cont=f.read()
print(cnt)
a=0
const=0
l=0
u=0
for ch in cont:
if (ch.islower()):
l+=1
elif(ch.isupper()):
u+=1
ch=ch.lower()
if( ch in ['a','e','i','o','u']):
v+=1
elif (ch in['b','c','d','f','g',
'h','j','k','l','m',
'n','p','q','r','s',
't','v','w','x','y','z']):
Cons+=1
f.close()
print("Vowels are : ",v)
print("consonants are : ",const)
print("Lower case letters are : ",l)
print("Upper case letters are : ",u)
count()
Practical 14
Program to create a binary file to store Roll No. & Name,
search any roll No. And display the name
import pickle
while True:
rollno = int(input("Enter your rollno: "))
name = input("Enter your name: ")
d = [rollno, name]
f = open("Student.dat", "wb")
pickle.dump(d, f)
choice = input("enter more records: y/n")
if choice== "N":
break
f.close()
f = open("Student.dat", "rb")
rno = int(input("Enter the roll no to search: "))
pt = 0
try:
while True:
r = pickle.load(f)
if rno == r[0]:
print (rollno, name)
pt = 1
except:
if pt == 0:
print("Record does not exist")
f.close( )
Practical 15
Program to create a binary file to store Roll no, Name,
Marks and update marks of entered Roll No.
import pickle
record=[]
while True:
roll=int(input("Enter roll no: "))
name=input("Enter name of student: ")
marks=int(input("Enter marks of student: "))
data=[roll,name,marks]
record.append(data)
choice=input("To enter more press y/n:")
if choice =='N':
break
f=open("student",'wb')
pickle.dump(record,f)
f.close()
f=open("student",'rb')
import pickle
f=open("student",'rb+')
stud=pickle.load(f)
found=0
rollno=int(input("Enter roll no to be searched:"))
for i in stud:
rno=i[0]
if rno==rollno:
print("Current name is:", i[1])
i[2]= input("New marks:")
found = 1
break
if found == 1:
f.seek(0)
pickle.dump(stud, f)
print("Marks Updated!!!")
f.close()
Practicle 16
Program to read the content of a file line by line and write
it to another file except for the lines containing "a" or "A"
def simpleA():
f=open("article.txt","r")
g=open("article.txt","w")
while True:
line=f.readline()
if line==" ":
break
if "a" not in line:
f1.write(line)
f.close()
g.close()
simpleA()
Practical 17
Program to create CSV file and store Empno, Name,
Salary and search any Empno and display name, salary.
import csv
a=[]
b = int(input("enter no. of element"))
for i in range(b):
emp=int(input("enter empnumber "))
name=input("enter name")
salary=int(input("enter the salary"))
c=[emp,name,salary]
a.append(c)
l=['empnumber','name','salary']
with open("try.csv","w",newline='') as f:
w=csv.writer(f,delimiter=',')
w.writerow(l)
w.writerows(a)
with open("try.csv","r",newline='') as f:
w=csv.reader(f)
k=input("enter empnumber")
for i in w:
global m
m=0
if k == i[0]:
m=1
print("name",i[1])
print("salary",i[2])
break
if m==0:
print("does not exist")
Practical 18
Program to generate a random no. 1-6 simulating a dice
import random
m=input("press enter to roll the dice")
s= random.randint(1,6)
print("dice rolled ",s)
Practical 19
Program to implement a stack in python using list
a=[]
def push(w):
a.append(w)
def pop():
z= a.pop()
print("item removed",z)
while True:
x= int(input('''1 to push an element 2 to pop an element 3 to
exit'''))
if x==1:
b=input("what do you want to enter")
push(b)
elif x==2:
pop()
elif x == 3:
break
print(a)
Practical 20
Program to take 10 sample phishing emails and find the
most common occurring.
a=[]
a=[]
for i in range(10):
c=input("enter the email")
a.append(c)
def d(List):
counter = 0
num = List[0]
for i in List:
frequency = List.count(i)
if frequency> counter:
counter = frequency
num = i
return num
print("most common phishing email is, ",d(a))
Practical 21
Program to connect with database and store records of
employee and display records.
import mysql.connector
a= mysql.connector.connect(host="localhost" ,user="root"
,passwd="1234",database="project")
b=a.cursor()
try:
b.execute("create table emp(id int(30),name varchar(30), salary
int(30))")
except:
pass
c=int(input("enter the no. elements"))
for i in range(c):
id=int(input("enter id "))
name=input("enter name")
salary=int(input("enter salary"))
b.execute("insert into emp
values(%s,%s,%s)",(id,name,salary))
a.commit()
b.execute("select * from emp")
d=b.fetchall()
for i in d:
print(i)