Professional Documents
Culture Documents
SCIENCE
PRACTICAL FILE
ARYAN VARMA
XII C 07
RAJHANS VIDYALAYA
RAJHANS
VIDYALAYA
ANDHERI-WEST
MUMBAI
CERTIFICATE
This is to certify that this computer practical file has been completed
by
of class 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.
li=[]
n=int(input("Enter size of list "))
for i in range(0,n):
e=int(input("Enter element of list "))
li.append(e)
length=len(lst)
count=0
for i in range(0,length):
if element==lst[i]:
count+=1
if count==0:
print(element,"not
found")
else:
lowercase=uppercase=0
digit=alphabet=0
for a in line:
if a.islower():
lowercase+=1
elif a.isupper():
uppercase+=1
elif a.isdigit():
digit+=1
elif a.isalpha():
alphabet+=1
else:
pass
return lowercase+uppercase,digit,uppercase,lowercase
line=input("enter string")
a,b,c,d=statementl(line)
print("Number of uppercase:",c)
print("Number of lowercase:",d)
print("Number of digits:",b)
print("Number of alphabet:",a)
6)
def mybuzz(n):
if n%3==0:
return "Fizz"
elif n%5==0:
return "Buzz"
elif n%3==0 and n%5==0:
return "Fizzbuzz"
else:
return n
def tonnetokg(b):
kg=0.001
print(b,"tonnes is equal to",b/kg,"kg")
def kgtopound(c):
kg=2.20462
print(c,"kg is equal to",c*kg,"pounds")
def
poundtokg(d):
kg=2.20462
print(d,"pounds is equal to",d/kg,"kg")
choice=input("enter y for help")
if choice=='y':
help()
n=int(input("enter
choice")) if n==1:
x=int(input("enter weight in kg"))
kgtotonne(x)
elif n==2:
x=int(input("enter weight in tonne"))
tonnetokg(x)
elif n==3:
x=int(input("enter weight in kg"))
kgtopound(x)
elif n==4:
x=int(input("enter weight in pound"))
poundtokg(x)
else:
print("invalid choice")
else:
print("invalid choice")
8)
def milestokm(a):
'''Returns the converted length from miles to km'''
return a*MtoK
def kmtomiles(a):
'''Returns the converted length from km to miles'''
return a/MtoK
def feettoinches(a):
'''Returns the converted length from feet to inches'''
return a*FtoI
def inchestofeet(a):
'''Returns the converted length from inches to feet'''
return a/FtoI
# constants
MtoK = 1.609344 #constant value of 1 mile in
km FtoI = 12 #constant value of 1 feet in inches
# MassConversion.py
'''Conversion between units of mass'''
# functions
def kgtotonne(x):
'''Returns the converted mass from kg to tonnes'''
return x*KtoT
def tonnetokg(x):
'''Returns the converted mass from tonne to kgs'''
return x/KtoT
def kgtopound(x):
'''Returns the converted mass from kg to pounds'''
return x*KtoP
def poundtokg(x):
'''Returns the converted mass from pounds to kgs'''
return x/KtoP
# constants
KtoT = 0.001 #constant value of 1 kg in tonnes
KtoP = 2.20462 #constant value of 1 kg in
pounds
import UnitConverter.lengthconversion as lc
import UnitConverter.MassConversion as
mc length = 10
mass = 30
print(lc.feettoinches(length))
print(mc.kgtopound(mass))
9)
import pickle
with open("emp.txt","wb") as fh:
stu={}
for i in range(0,2):
eno=int(input("enter employee no"))
n=input("enter name")
salary1=int(input("salary"))
stu['empno']=eno
stu['name']=n
stu['salary']=salary1
pickle.dump(stu,fh)
fh.close()
try:
with open("emp.txt","rb") as fh:
while True:
stu=pickle.load(fh)
print("this is record no",i)
print(stu)
i=i+1
except EOFError:
fh.close()
10)
f1=open("story.txt","r")
f2=open("copy.txt","w")
l=f1.readlines()
for line in l:
t=line.split()
for x in t:
f2.write(x)
f2.write('-'
)
f2.write('\n')
f1.close()
f2.close()
11)
import pickle
a=open("Employee.dat","wb")
ch=int(input("Enter no of records you want to enter:"))
for i in range (ch):
eno=int(input("Enter employee no:"))
enam=input("Enter employee name:")
age=int(input("Enter employee age:"))
sal=int(input("Enter employee
salary:"))
dict={"Employee no":
eno,"Name":enam,"Age":age,"Salary":sal} pickle.dump(dict,a)
a.close()
a=open("Employee.dat","rb")
try:
while a:
inf=pickle.load(a)
if inf["Salary"]>=25000 and inf["Salary"]<=30000:
print(inf)
except EOFError:
print("End of
file")
12)
import pickle
a=open("Cust.txt","rb")
inp=input("Enter customer no")
cou=0
try:
while a:
inf=pickle.load(a)
if inf['Customer number']== inp:
print("Found!!!")
cou+=1
break
except EOFError:
print("End of
file")
if cou==0:
print("Not found")
13)
import csv
a=open("employee.csv","w",newline="")
w=csv.writer(a)
ch=int(input("Enter no of records you want to enter:"))
w.writerow(["Employee no","Employee
name","Department","salary"])
for i in range(ch):
eno=int(input("Enter employee no:"))
enam=input("Enter employee name:")
dept=(input("Enter employee department:"))
sal=int(input("Enter employee salary:"))
ls=[eno,enam,dept,sal]
w.writerow(ls)
a.close()
a=open("employee.csv","r",newline="")
w=csv.reader(a)
for i in w:
print(i)
a.close()
14)
import csv
a=open("employee.csv","r",newline="")
w=csv.reader(a)
count=0
for i in w:
print(i)
count+=1
print("No fo records:",count-1)
15)
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("empty stack")
else:
top=len(stk)-1
print(stk[top],"<---top")
for a in range(top-1,-1,-1):
print(stk[a])
stk=[]
top=None
ans='y'
while ans=='y':
ch=int(input("1-push,2-display"))
if ch==1:
bno=int(input("enter bookno"))
bname=input("enter
bookname") item=[bno,bname]
push(stk,item)
elif ch==2:
display(stk)
else:
print("invalid choice")
ans=input("y to
continue")
16) A
i) mysql> select * from club where sex='f';
+ + + + + + +
+
| coach_ID | coachname | age | sports | dateofapp | pay |
sex |
+ + + + + + +
+
| 2 | ravina | 34 | squash | 1998-02-19 | 1200 | f
|
+ + + + + + +
+
1 row in set (0.00 sec
ii) mysql> select * from club where pay>1000 order by dateofapp desc;
+ + + + + + + +
| coach_ID | coachname | age | sports | dateofapp | pay | sex |
+ + + + + + + +
| 2 | ravina | 34 | squash | 1998-02-19 | 1200 | f |
| 4 | shailya | 41 | basketball | 1998-02-19 | 1700 | m |
+ + + + + + +
+ 2 rows in set (0.10 sec)
mysql>9
B)
i) mysql> select * from graduate where ran=1 order by name;
+ + + + + + +
| sno | name | stipend | subject | average | ran |
+ + + + + + +
| 2 | DIVAKAR | 450 | COMPUTER SC. | 90 | 1 |
| 1 | DIVYA | 400 | PHYSICS | 68 | 1 |
| 4 | SABINA | 500 | CHEMISTRY | 57 | 1 |
+ + + + + +
+ 3 rows in set (0.02 sec)
ii) mysql> select name from graduate where name like '%na%';
+ +
| name |
+ +
| SABINA |
+ +
1 row in set (0.00 sec)
iii) mysql> update graduate
-> set stipend =stipend+500
-> ;
Query OK, 4 rows affected (0.14 sec)
Rows matched: 4 Changed: 4 Warnings: 0
connection()
cur=mydb.cursor()
cur.execute("Select * from customer where name like 'r%' ")
for i in cur:
print(i)
18)
import mysql.connector
def connection():
global mydb,cur
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="123456",
database="new"
)
connection()
cur=mydb.cursor()
cur.execute("update customer set sal=sal+2000")
mydb.commit
cur.execute("Select * from customer")
for i in cur:
print(i)
19)
import mysql.connector
def connection():
global mydb,cur
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="123456",
database="new"
)
connection()
cur=mydb.cursor()
cur.execute("Select * from customer where price>5000 and
price<9000")
for i in cur:
print(i)
20)
import mysql.connector
def connection():
global mydb,cur
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="123456",
database="new"
)
connection()
cur=mydb.cursor()
cur.execute("delete from customer where cno=5")
mydb.commit()
cur.execute("Select * from customer")
for i in cur:
print(i)