Final Sanjeev Pratical File
Final Sanjeev Pratical File
Final Sanjeev Pratical File
-SANJEEV ANEHOSUR
XII C 21
RAJHANS VIDYALAYA
ANDHERI-WEST
MUMBAI
CERTIFICATE
This is to certify that this computer practical file has been completed by
year 2022-2023.
____________________ ______________________
Date: Date:
____________________ ______________________
Date:
INDEX
Sr. Program
No.
for a in line:
if a.isdigit()!= True and a!= ' ':
alphacount+=1
if a.islower():
lowercount+=1
if a.isupper():
uppercount+=1
if a.isdigit():
digitcount+=1
OUTPUT:
PROGRAM 2:
#Program to find second largest number of a list of numbers.
a=[]
n=int(input("Enter number of elements:"))
for i in range(1,n+1):
b=int(input("Enter element:"))
a.append(b)
a.sort()
print("Second largest element is:",a[n-2])
OUTPUT:
PROGRAM 3
#Program to count frequency of a given element in a list of numbers
list = eval(input("Enter your list:"))
length = len(list)
a = int(input("Enter element:"))
count = 0
for i in range(length):
if a == list[i]:
count +=1
if count == 0:
print(a, "not in given list")
else:
print(a, "has frequency as", count, "in the list")
OUTPUT:
PROGRAM 4
#Program which takes as input a tuple T and returns the second largest
element in the tuple.
T = eval(input("Enter a tuple:"))
maxvalue= max(T)
length = len(T)
secmax = 0
for a in range(length):
if secmax < T[a] < maxvalue :
secmax = T[a]
print("Second Largest value is:", secmax)
OUTPUT:
PROGRAM 5:
#Program to define a function that finds number of letters, digits, upper
and lowercase letters
def str1(x):
u=l=0
a=d=0
for i in x:
if i.isdigit():
d=d+1
elif i.isalpha():
a=a+1
if i.isupper():
u=u+1
elif i.islower():
l=l+1
else:
pass
return d,a,u,l
p=input("Enter your string:")
str2=str1(p)
print("The number of digits, alphabets, upper case and lower case letters
are:",str2,"respectively")
OUTPUT:
PROGRAM 6
#Program to define function my_buzz
def my_buzz(x):
if x%3==0 and x%5==0:
print("fizzbuzz")
elif x%3==0:
print("fizz")
elif x%5==0:
print("buzz")
else:
print(x)
return
num1= int(input("Enter a number:"))
new1=my_buzz(num1)
OUTPUT:
PROGRAM 7
#Program to create module massconversion.py
#massconversion.py
def kgtotonne(a):
'''Returns the converted mass from kg to tonne'''
return a*kgtot
def tonnetokg(a):
'''Returns the converted mass from tonne to kg'''
return a/kgtot
def kgtopound(a):
'''Returns the converted mass from kg to pound'''
return a*kgtop
def poundtokg(a):
'''Returns the converted mass from pound to kg'''
return a/kgtop
#constants
kgtot= 0.001
kgtop= 2.20462
import massconversion as mc
value=int(input("Enter mass:"))
print("1. kg")
print("2. tonne")
print("3. pound")
vtype=int(input("Enter mass value type:(1,2 or 3):"))
if vtype==1:
ans1 = mc.kgtotonne(value)
print("Mass converted from kgs to tonne is", ans1)
ans2 = mc.kgtopound(value)
print("Mass converted from kgs to pound is", ans2)
elif vtype==2:
ans3 = mc.tonnetokg(value)
print("Mass converted from tonne to kgs is", ans3)
elif vtype==3:
ans4 = mc.poundtokg(value)
print("Mass converted from pound to kgs is", ans4)
OUTPUT:
PROGRAM 8:
#lengthconversion.py
def miletokm(x):
return x*mtokm
def kmtomile(x):
return x/mtokm
def feettoinches(x):
return x*ftoi
def inchestofeet(x):
return x/ftoi
#constants
mtokm= 1.609344
ftoi= 12
#massconversion.py
def kgtotonne(a):
return a*kgtot
def tonnetokg(a):
'''Returns the converted mass from tonne to kg'''
return a/kgtot
def kgtopound(a):
return a*kgtop
def poundtokg(a):
return a/kgtop
#constants
kgtot= 0.001
kgtop= 2.20462
import lengthconversion as lc
import massconversion as mc
print("Which conversion?")
if ch==1:
print("2. km to mile")
if v==1:
a= lc.miletokm(x)
print("length in km:",a)
elif v==2:
a= lc.kmtomile(x)
print("length in mile:", a)
elif v==3:
a= lc.feettoinches(x)
print("length in inches:",a)
elif v==4:
a= lc.inchestofeet(x)
print("length in feet:",a)
else:
print("Invalid Choice!!")
elif ch==2:
value=int(input("Enter mass:"))
print("1. kg")
print("2. tonne")
print("3. pound")
if vtype==1:
ans1 = mc.kgtotonne(value)
ans2 = mc.kgtopound(value)
elif vtype==2:
ans3 = mc.tonnetokg(value)
elif vtype==3:
ans4 = mc.poundtokg(value)
else:
print("Invalid Choice!!")
else:
print("Invalid Choice!!")
OUTPUT:
PROGRAM 9
#Program to create text file emp.txt
file=open('emp.txt', "w")
for i in range(5):
print("Enter details for employee",(i+1),"below")
no=int(input("Employee no:"))
name=input("Name:")
salary=int(input("Salary:"))
file.write(str(no)+','+name+','+str(salary)+'\n')
file.close()
file=open("emp.txt", "r")
print(file.read())
file.close()
OUTPUT:
PROGRAM 10
#Program to read text file and replace space with hyphen symbol
file1=open("story.txt", "r")
file2=open("identical.txt","w")
text=file1.read()
file2.write(text.replace(' ', '-'))
file1.close()
file2.close()
file2=open("identical.txt", "r")
print(file2.read())
file2.close()
PROGRAM 10
#Program to read text file and replace space with hyphen symbol
file1=open("story.txt", "r")
file2=open("identical.txt","w")
text=file1.read()
file2.write(text.replace(' ', '-'))
file1.close()
file2.close()
file2=open("identical.txt", "r")
print(file2.read())
file2.close()
OUTPUT:
PROGRAM 11
#Program to create binary file employee and display records.
import pickle
file=open("Employee", "wb")
rec={}
emp1={'Empno':1054, 'Name': "Mark", 'Salary': 34000}
emp2={'Empno':1057, 'Name': "Johnny", 'Salary': 26000}
emp3={'Empno':1055, 'Name': "TY", 'Salary': 36000}
emp4={'Empno':1056, 'Name': "Nana", 'Salary': 28000}
pickle.dump(emp1,file)
pickle.dump(emp2,file)
pickle.dump(emp3,file)
pickle.dump(emp4,file)
file.close()
file=open("Employee", "rb")
try:
while True:
rec=pickle.load(file)
print(rec)
except EOFError:
file.close()
file=open("Employee", "rb")
print()
print("Displaying records of employees getting salaries between 25000
to 30000:")
try:
while True:
rec=pickle.load(file)
if 25000< rec["Salary"]<30000:
print(rec)
except EOFError:
file.close()
OUTPUT:
PROGRAM 13
#Program to create employee.csv file
import csv
file=open("employee.csv", "w")
empwriter=csv.writer(file)
empwriter.writerow(['EmpNo', 'Name', 'Salary'])
for a in range(3):
print('Employee', a+1, ':')
empno=input('Enter employee no.')
name=input('Enter name:')
salary=input('Enter salary:')
emp=[empno, name, salary]
empwriter.writerow(emp)
file.close()
file=open('employee.csv', 'r', newline='\r\n')
empreader=csv.reader(file)
for emp in empreader:
print(emp)
file.close()
OUTPUT:
PROGRAM 14
#Program to count the number of records present in the employee.csv
file excluding the header.
import csv
file=open("employee.csv", "r", newline='\r\n')
count=0
empreader=csv.reader(file)
for rec in empreader:
count+=1
print("Number of records in employee.csv file:", count-1)
file.close()
OUTPUT:
PROGRAM 15
"""
Stack: implemented as a list
top: integer having position of topmost element in Stack
"""
def cls():
print("\n"*100)
def isEmpty(stk):
if stk==[]:
return True
else:
return False
def Push(stk, item):
stk.append(item)
top=len(stk)-1
def Display(stk):
if isEmpty(stk):
print("Stack empty")
else:
top=len(stk)-1
print(stk[top], "<-top")
for a in range(top-1, -1, -1):
print(stk[a])
#_main_
Stack=[]
top=None
while True:
cls()
print("Stack Operations")
print("1. Push")
print("2. Display stack")
print("3. Exit")
ch=int(input("Enter your choice(1-3):"))
if ch == 1:
bno=int(input("Enter Book no. to be inserted:"))
bname=input("Enter Book name to be inserted:")
item=[bno, bname]
Push(Stack, item)
input()
elif ch==2:
Display(Stack)
input()
elif ch==3:
break
else:
print("Invalid choice!")
input()
OUTPUT:
PROGRAM 16 A:
Table code:
Table:
i) Display all information about the swimming coaches in the club or
female coaches.
Table code:
Table:
i). Display the names of those who have obtained rank 1 sorted by
NAME.
ii). Display the names with substring “NA” or average is more than 70.
v). Display a report showing names, subject, average and bonus (15%)
for all graduates.
Table:
Program 17:
# display all the records where customer name starts with “R”
import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="1
23456",database="sanjeev")
mycursor=mydb.cursor()
mycursor.execute(st)
data=mycursor.fetchall()
print(row)
OUTPUT:
PROGRAM 18:
OUTPUT:
PROGRAM 19:
OUTPUT:
PROGRAM 20:
OUTPUT: