Final Sanjeev Pratical File

Download as pdf or txt
Download as pdf or txt
You are on page 1of 36

COMPUTER PRACTICAL 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

Smera Agrawal of class XII C and board roll number_______, in

partial fulfillment of the curriculum of the CENTRAL BOARD OF


SECONDARY

EDUCATION leading to the award of All India Senior School Certificate


for the

year 2022-2023.

____________________ ______________________

External Examiner Internal Examiner

Date: Date:

____________________ ______________________

SCHOOL SEAL PRINCIPAL

Date:
INDEX

Sr. Program
No.

1 Program to print statistics of a line

2 Program to find second largest number of a list of numbers

3 Program to count frequency of a given element in a list of


numbers

4 Program that returns the second largest element in the tuple

5 Program to define a function that finds number of letters,


digits, upper and lowercase letters

6 Program to define function mybuzz

7 Program to create a module MassConversion.py

8 Create a package from two modules

9 Program to create a text file emp.txt and display all records


10 Program to read a text file and create an identical file

11 Create a binary file “employee” that stores the records of

employees and display them

12 Program to search Customer number from the binary


Cust.txt

13 Program to write data onto “employee.csv”

14 Program to count the exact number of records present in the


employee.csv

15 Program to implement a stack

16 A) Create the table CLUB

16 B) Create the table GRADUATE

17 Display all records of Customer table where customer name


starts with “R”.

18 Increase the amount by 2000 for all the records

19 Search those customers whose salary is between 5000 to


9000
20 Delete the customer whose CNO is 5
PROGRAM 1
#Program to print statistics of a line
line = input("Enter a line:")
lowercount = uppercount = 0
digitcount = alphacount = 0

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

print("Number of uppercase letters:", uppercount)


print("Number of lowercase letters:", lowercount)
print("Number of alphabets:", alphacount)
print("Number of digits:", digitcount)

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:

#create a package of two modules

#lengthconversion.py

def miletokm(x):

"Return value in kilometer from miles"

return x*mtokm

def kmtomile(x):

"Return value in miles from kilometer"

return x/mtokm

def feettoinches(x):

"Return value in inches from feet"

return x*ftoi

def inchestofeet(x):

return x/ftoi

#constants

mtokm= 1.609344

ftoi= 12

#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 lengthconversion as lc

import massconversion as mc

print("Which conversion?")

print("1. length conversion")

print("2. mass conversion")

ch=int(input("Enter your choice:"))

if ch==1:

print("1. mile to km")

print("2. km to mile")

print("3. feet to inches")

print("4. inches to feet")


v= int(input("Enter conversion type:"))

if v==1:

x= float(input("Enter length in miles:"))

a= lc.miletokm(x)

print("length in km:",a)

elif v==2:

x= float(input("Enter length in km:"))

a= lc.kmtomile(x)

print("length in mile:", a)

elif v==3:

x= float(input("Enter length in feet:"))

a= lc.feettoinches(x)

print("length in inches:",a)

elif v==4:

x= float(input("Enter length in inches:"))

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")

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)

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.

ii) Display names of all coaches with their date of appointment in


descending order only if pay is more than 1000.

iii) Increase the pay of coaches by 2000.


iv) Display the names of substring “YA” or age is more than 30.

v) Display a report showing coachname, pay, age and bonus(15% of


pay) for all the coaches.
PROGRAM 16 B:

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.

iii). Increase the stipend by 500.


iv). Display all the records whose SUBJECT is PHYSICS and RANK is 1.

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()

st="select * from customer where name like 'R%'"

mycursor.execute(st)

data=mycursor.fetchall()

for row in data:

print(row)

OUTPUT:
PROGRAM 18:

# increase the amount by 2000 for all the records


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="1
23456",database="sanjeev")
mycursor=mydb.cursor()
st="update customer set salary= salary +{}".format(2000)
mycursor.execute(st)
mydb.commit()
st2="select * from customer"
mycursor.execute(st2)
data=mycursor.fetchall()
for row in data:
print(row)

OUTPUT:
PROGRAM 19:

# search those customers whose salary is between 5000 to 9000


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="1
23456",database="sanjeev")
mycursor=mydb.cursor()
st="select * from customer where salary between {} and
{}".format(5000,9000)
mycursor.execute(st)
data=mycursor.fetchall()
for row in data:
print(row)

OUTPUT:
PROGRAM 20:

# delete the customer whose CNO is 5


import mysql.connector
mydb=mysql.connector.connect(host="localhost",user="root",passwd="1
23456",database="smera")
mycursor=mydb.cursor()
st="delete from customer where cno={}".format(5)
mycursor.execute(st)
mycursor.execute("select * from customer")
data= mycursor.fetchall()
for row in data:
print(row)

OUTPUT:

You might also like