BADAPLINrecord
BADAPLINrecord
KANAKAPURA, KARNATAKA
PRACTICAL FILE
For
AISSCE 2025 Examination
[As a part of the Computer Science Course (083)]
SUBMITTED BY
KESAR JAIN K
JAIN INTERNATIONAL RESIDENTIAL SCHOOL
KANAKAPURA, KARNATAKA
Examination 2025.
………………………… ……………………………..
Signature of External Examiner Signature of Internal Examiner
OUTPUT
enter number1:12
enter number2:11
the sum is 23
the difference is 1
the product is 132
the quotient is 1
PROGRAM 2
AIM: a program to accept a number and print if the
number is an Armstrong number or not.
a=int(input('enter the number:'))
l=len(str(a))
s=0
t=a
while t>0:
j=t%10
s+=j**l
t=t//10
if s==a:
print('It is an Armstrong no')
else:
print('It is not an Armstrong no')
OUTPUT:
enter the number:123
It is not an Armstrong no
PROGRAM 3
AIM: a program to accept a number and print if the
number is prime or not.
d=int(input('enter a number:'))
s=0
for i in range(2,(d//2+1)):
if (d%i==0):
s=1
break
if(s==0):
print("it is a prime number")
else:
print("it is not a prime number")
OUTPUT:
enter a number:12
it is not a prime number
PROGRAM 4
OUTPUT:
enter the number:4
the factorial is 24
PROGRAM 5
AIM: a program to create a function words to accept a
string and print the number of words in the string,
function palindrome to print if the string is palindrome
and function count to count the occurrence of the
letter ‘T’ in the string.
def words():
a=input('enter string:')
y=a.split()
z=len(y)
print('the number of words in the string is:',z)
def palindrome():
b=input('enter string:')
if b[::-1]==b:
print('it is a palindrome')
else:
print('it is not a palindrome')
def count():
s=0
c=input('enter string:')
for i in c:
if i=='t':
s+=1
print('the number of Ts in the string is',s)
words()
palindrome()
count()
OUTPUT:
enter string:kesar jain computer science
the number of words in the string is: 4
enter string:mom
it is a palindrome
enter string:khyati is studying
the number of Ts in the string is 2
PROGRAM 6
AIM: A Program to enter a list of elements and pass
the list to a function and display the elements and
index of the non-zero elements.
def elements(a):
for i in range(0,len(a)):
if(a[i]!=0):
print(i,a[i])
l=eval(input('enter the values'))
elements(l)
OUTPUT:
enter the values12,12,0,0,0,0,0
0 12
1 12
PROGRAM 7
AIM: A program to find area of different shapes using
user defined functions
choice='yes'
def circle(r):
print('the are of the circle is: ',3.14*r**2)
def rectangle(l,b):
print('the area of rectangle is: ',l*b)
def square(s):
print('the area of the square is: ',s*s)
def triangle(b,h):
print('the area of triangle is: ',0.5*b*h)
while choice=='yes':
print('1.circle')
print('2.rectangle')
print('3.square')
print('4.triangle')
choice2=int(input('enter shape choice: '))
if choice2==1:
r=int(input('enter the radius: '))
circle(r)
elif choice2==2:
l=int(input('enter the length: '))
b=int(input('enter the breadth: '))
rectangle(l,b)
elif choice2==3:
s=int(input('enter the side: '))
square(s)
else:
b=int(input('enter the base: '))
h=int(input('enter the height: '))
triangle(b,h)
choice=input('do you want to continue? yes/no:')
OUTPUT:
1.circle
2.rectangle
3.square
4.triangle
enter shape choice: 1
enter the radius: 1
the are of the circle is: 3.14
do you want to continue? yes/no:yes
1.circle
2.rectangle
3.square
4.triangle
enter shape choice: 2
enter the length: 2
enter the breadth: 2
the area of rectangle is: 4
do you want to continue? yes/no:no
PROGRAM 8
AIM: A program to read a text file line by line and
display each word separated by a ‘#’.
a=open(r'C:\Users\students\Documents\cprogram.txt')
b=a.read()
c=b.split()
for i in c:
print(i,"#",end="")
OUTPUT:
kesar #jain #12 #d #jain #international #residential
#school #bangalore #karnataka #salem #tamilnadu #
PROGRAM 9
AIM: To read a text file and display the number of
vowels/consonants/capital and small letters.
a=open(r'C:\Users\students\Documents\cprogram.txt')
b=a.read()
v=0
c=0
d=0
e=0
for i in b:
if i in ['a','e','i','o','u', 'A','E','I','O','U']:
v+=1
else:
c+=1
a.seek(0)
for i in b:
if i>='A' and i<='Z':
d+=1
elif i>='a' and i<='z':
e+=1
print('the number of vowels are',v)
print('the number of consonants are',c)
print('the number of capital letters are',d)
print('the number of small letters are',e)
OUTPUT:
the number of vowels are 33
the number of consonants are 56
the number of capital letters are 10
the number of small letters are 66
PROGRAM 10
AIM: A program to remove all the lines that contain
the character ‘a’ in a file and write it to another file.
a=open(r'C:\Users\students\Documents\csprogra.txt')
b=open(r'C:\Users\students\Documents\file.txt',"w")
l=[]
c=a.readlines()
for i in c:
if 'a' not in i:
l.append(i)
b.writelines(l)
b.close()
OUTPUT:
computer science
PROGRAM 11
AIM: A Program to read a text file and count the
number of
occurrence of a word in the text file.
s=0
a=open(r'C:\Users\students\Documents\csprogra.txt')
b=input('enter the word:')
c=a.read()
e=c.split()
for i in e:
if i==b:
s+=1
print(s)
OUTPUT:
enter the word:Jain
2
PROGRAM 12
AIM: Create a binary file with roll number and name.
Input a roll number and search the student with a
specific roll number and display the details.
import pickle
l=[]
def write():
a=open(r'C:\Users\students\empty2.dat','wb')
b=int(input('enter the number of students:'))
for i in range(1,b+1):
r=int(input('enter the rollno:'))
n=input('enter the name:')
l.append([r,n])
pickle.dump(l,a)
a.close()
def find():
b=open(r'C:\Users\students\empty2.dat','rb+')
roll=int(input('enter the rollno:'))
c=pickle.load(b)
for i in c:
if(i[0]==roll):
print(i[1])
b.close()
write()
find()
OUTPUT:
enter the number of students:3
enter the rollno:1
enter the name:a
enter the rollno:2
enter the name:b
enter the rollno:3
enter the name:c
enter the rollno:1
a
PROGRAM 13
AIM:a program to create a binary file with roll
number,name and marks. Input a roll number and
update the marks.
import pickle
l=[]
def enter():
a=open(r'C:\Users\students\empty2.dat','wb')
s=int(input('enter the number of students:'))
for i in range(0,s):
n=input('enter name:')
r=int(input('enter rollno:'))
m=int(input('enter marks:'))
l.append([n,r,m])
pickle.dump(l,a)
a.close()
def search():
a=open(r'C:\Users\students\empty2.dat','rb+')
n1=int(input('enter the rollno'))
c=pickle.load(a)
m1=int(input('enter marks:'))
for i in c:
if i[1]==n1:
i[2]=m1
a.seek(0)
pickle.dump(c,a)
a.close()
def display():
a=open(r'C:\Users\students\empty2.dat','rb+')
d=pickle.load(a)
for i in d:
print(i)
enter()
search()
display()
OUTPUT:
enter the number of students:3
enter name:a
enter rollno:1
enter marks:100
enter name:b
enter rollno:2
enter marks:100
enter name:c
enter rollno:3
enter marks:100
enter the rollno1
enter marks:95
['a', 1, 95]
['b', 2, 100]
['c', 3, 100]
PROGRAM 14:
AIM: a program to create the csv file which contains
the employee details and to search the particular
employee based on emp no and display the details.
import pickle
l=[]
def enter():
a=open(r'C:\Users\students\Documents\
empty2.dat','wb')
b=int(input('enter the number of employees:'))
for i in range(0,b):
e=input('enter employee name:')
n=int(input('enter employee number:'))
s=int(input('enter the salary:'))
l.append([e,n,s])
pickle.dump(l,a)
a.close()
def find():
b=open(r'C:\Users\students\Documents\
empty2.dat','rb+')
e2=input('enter the employee name:')
c=pickle.load(b)
for i in c:
if i[0]==e2:
print(i[1],i[2])
b.close()
enter()
find()
OUTPUT:
enter the number of employees:3
enter employee name:a
enter employee number:1
enter the salary:100
enter employee name:b
enter employee number:2
enter the salary:200
enter employee name:c
enter employee number:3
enter the salary:300
enter the employee name:c
3 300
PROGRAM 15:
AIM:to create a CSV file by entering user-id and
password, read and search the password for given user-
id.
import csv
def addrec():
with open('login.csv','w',newline='') as f:
b=csv.writer(f)
b.writerow(['UserID','Password'])
ans='y'
while ans in 'Yy':
print('Enter Login Details:')
uID=input("Enter the UserID:")
p=input("Enter the Password :")
b.writerow([uID,p])
ans=input("Do you want to add another
record(y/n):")
print("record stored")
def searchrec():
with open('login.csv','r') as f:
b=csv.reader(f)
ans='y'
while ans in 'Yy':
found=False
uID=input('Enter the UserID which you want to
search:')
for r in b:
if str(uID) in r:
print("User ID:",r[0],'\nPassword :',r[1])
found=True
break
if found==False:
print('Record not found')
ans=input("Do you want to search another
record(y/n):")
addrec()
searchrec()
OUTPUT:
Enter employ details:
Enter the emp no:1525
Enter emp name :piriyanka attitude
Enter emp salary:10
Do you want to add another record(y/n):y
Enter employ details:
Enter the emp no:1234
Enter emp name :prasun
Enter emp salary:100000000
Do you want to add another record(y/n):n
record stored
Enter the emp no which you want to search:1525
Emp no: 1525
Emp name : piriyanka attitude
Emp salary: 10
Do you want to search another record(y/n):n
PROGRAM 16
l=[]
def push():
n=int(input("enter"))
l.append(n)
print(l)
def pop():
if l==[] or len(l) == 0:
print('stack empty')
else:
l.pop()
def disp():
if l==[]:
print('the stack is empty')
else:
print(l[::-1])
def peak():
if l==[]:
print("stack empty")
else:
print(l[-1])
choice = 'yes'
while choice == 'yes':
print('1.push')
print('2.pop')
print('3.display')
print('4.peak')
choice1 = input('enter the choice')
if choice1 == '1':
push()
elif choice1 == '2':
pop()
elif choice1 == '3':
disp()
elif choice1 == '4':
peak()
choice = input('do you want to continue')
OUTPUT:
1.push
2.pop
3.display
4.peak
enter the choice1
enter11
[11]
do you want to continueno
PROGRAM 17
import mysql.connector as dd
y=
dd.connect(host="localhost",user="root",password="jirs",cha
rset="utf8",database="school")
x=y.cursor()
def ins():
for i in range(0,3):
pid=int(input("id of the product "))
pname=input("name of product")
price=input("price")
c="insert into product values(%s,%s,%s);"
t=(pid,pname,price)
x.execute(c,t)
y.commit()
def display():
q="select * from product where pid = 12;"
x.execute(q)
for i in x :
print(i)
ins()
display()
OUTPUT:
id of the product 12
name of productpen
price100
id of the product 11
name of productpencil
price50
id of the product 13
name of productbook
price300
PROGRAM 18
import mysql.connector as dd
y=dd.connect(host="localhost",user="root",password="jirs",c
harset="utf8",database="school")
x=y.cursor()
def update1 ():
pid=int(input('pid:'))
pname=input('pname:')
price=input('price:')
q="update product set price = %s,pname = %s where pid
= %s ;"
t=(price,pname,pid)
x.execute(q,t)
y.commit()
def display():
q="select * from product ;"
x.execute(q)
for i in x :
print(i)
update1()
display()
OUTPUT:
pid:12
pname:pens
price:1000
(12, 'pens', 1000)
(11, 'pencil', 50)
(13, 'book', 300)
PROGRAM 19
import mysql.connector as dd
y=
dd.connect(host="localhost",user="root",password="jirs",cha
rset="utf8",database="school")
x=y.cursor()
def delete1():
pid=int(input("enter the product id:"))
q="delete from product where pid=%s;"
t=(pid,)
x.execute(q,t)
y.commit()
def display():
q="select * from product;"
x.execute(q)
for i in x :
print(i)
display()
delete1()
display()
OUTPUT:
(12, 'pens', 1000)
(11, 'pencil', 50)
(13, 'book', 300)
enter the product id:11
(12, 'pens', 1000)
(13, 'book', 300)
PROGRAM 20
import mysql.connector as dd
y=dd.connect(host="localhost",user="root",password="jirs",c
harset="utf8",database="school")
x=y.cursor()
def disp2():
q="select * from product where price >= 1000;"
x.execute(q)
for i in x :
print(i)
disp2()
OUTPUT:
(12, 'pens', 1000)
MY SQL QUERIES
PROGRAM 1
OUTPUT
EMPTY SET
OUTPUT
accno fd_amount
1001 300000
1002 200000
1003 400000
| CUST_NAME | FD_AMOUNT |
| PRASUN | 200000 |
| NAYO | 100000
OUTPUT
EMPTY SET
OUTPUT
6.To display the details of all the Fixed Deposits whose FD Amount is
in the range 40000-50000
select * from workers where fd_amount>=400000 and fd_amount<=500000;
OUTPUT:
accno cust_name fd_amount months int_rate fd_date
1003 shriram 400000 36 5 2018-03-01
7.To display the Customer name and FD amount for all the loans for
which thenumber of months is 24,36 or 48(using in operator)
select cust_name,fd_amount from workers where months=24 or months=36
or months=48;
OUTPUT
cust_name fd_amount
priyanka 300000
prasun 200000
shriram 400000
250000.0000
10.To display the total FD amount which started in the year 2018.
select sum(fd_amount) from workers where year(fd_date)=2018;
OUTPUT
sum(fd_amount)
900000
11.To display the details about all the FDs whose rate of
interest is not in the range 6% to 7%
select * from workers where int_rate>=6.00 and int_rate<=7.00;
OUTPUT
accno cust_name fd_amount months int_rate fd_date
1001 priyanka 300000 36 6 2018-07-01
1002 prasun 200000 48 6.75 2018-03-22
12.To display the details about all the FDs whose customer name
doesn’t contain the character “a”.
select * from workers where cust_name not like "%a%";
OUTPUT
Empty set
13.To update the Interest rate of all the bank Customers from 5.55 to
6.80
OUTPUT
update workers set int_rate=6.80 where int_rate=5.55;
PROGRAM 2:
1.To display the natural join of the tables items and traders.
select * from items natural join traders;
OUTPUT
| tcode | code | iname | price | qty | company | tname
| city |
| 101 | 1 | coat | 600 | 5 | modi | prasun | angul
|
| 101 | 2 | boat | 1000 | 10 | das | prasun | angul
|
| 103 | 3 | pen | 100 | 50 | orio | shriram | halo
|
| 104 | 4 | book | 25 | 15 | das | nayo |
hyderabad |
4.To display the Item name and Trader name of all the items
that are either from HALO or ANGUL
select iname,tname from items natural join traders where
city in("halo","angul");
OUTPUT
| iname | tname |
| coat | prasun |
| boat | prasun |
| pen | shriram |
2)To display the names and date of joining of all the workers in
Kolkata.
select name doj from worker natural join dept where city like
"kolkata";
OUTPUT
| doj |
| priyanka |
5) To display the names of all the departments where more than one
worker are available.
select department,dcode from dept natural join worker group by
dcode having count(*)>1;
OUTPUT
| department | dcode |
| media | d01 |
7)To display the details about all the workers whose Wno is either
1003 , 1005 or 1007
select * from worker where wno in (1003,1005,1007);
OUTPUT
| wno | name | doj | dob | gender | dcode |
| 1003 | priyanka | 2016-08-12 | 1989-10-10 | female | d03 |
| 1005 | nayo | 2014-01-17 | 1984-10-19 | female | d01 |
10) To display the details of all the male workers in the finance
department.
select * from worker natural join dept where gender="female" and
department="finance";
OUTPUT
Dcode wno name doj dob gender department city
d03 1003 priyanka 2016-08-12 1989-10-10 female finance kolkata
PROGRAM 4
1.To show all the information about the patients of the cardiology
department.
select * from hospital where dept="cardiology";
OUTPUT
| pno | name | age | dept | doa | charges | sex |
| 3 | nayo | 45 | cardiology | 2018-12-19 | 400 | f |
2.To list the names of female patients who are either in the
orthopaedic or surgery department.
select name from hospital where sex="f" and (dept="ortho" or
dept="surgery");
OUTPUT
Empty set
3.To display various departments in the hospital.
select distinct dept from hospital;
OUTPUT
| dept |
| surgery |
| ent |
| cardiology |
| ortho |
7.To display the details about all the patients in the reverse
alphabetical order of their names.
select * from hospital order by name desc;
OUTPUT
| pno | name | age | dept | doa | charges | sex |
| 2 | shriram | 24 | ent | 2019-01-01 | 400 | f |
| 1 | prasun | 65 | surgery | 2018-02-23 | 600 | m |
| 3 | nayo | 45 | cardiology | 2018-12-19 | 400 | f |
| 4 | ali | 14 | ortho | 2018-10-01 | 600 | m |
10.To display the names of the patients who are charged in the range
300 and 400
select name from hospital where charges between 300 and 400;
OUTPUT
| name |
| shriram |
| nayo |
11.To display the number of patients who are aged above 30.
select count(*) from hospital where age>30;
OUTPUT
| count(*) |
| 2|
1.To show all information about the golf coaches in the Club.
select * from club where sports="golf";
OUTPUT
| coach_id | name | age | sports | doa | pay | sex
| 1 | prasun | 35 | golf | 1996-03-27 | 1000 | m |
| 5 | pratibha | 35 | golf | 1998-01-12 | 3000 | f |
2.To list the names of all coaches with their date of appointment in
descending order.
select name from club order by doa desc;
OUTPUT
| name |
| shriram |
| nayo |
| pratibha |
| priyanka |
| prasun |
3.select sports ,min(pay),max(pay),avg(pay) from club group by
sports;
OUTPUT
| sports | min(pay) | max(pay) | avg(pay) |
| football | 1500 | 1500 | 1500.0000 |
| golf | 1000 | 3000 | 2000.0000 |
| karate | 1200 | 1200 | 1200.0000 |
| squash | 2000 | 2000 | 2000.0000 |
6.To display the details about the female coaches in the club.
select * from club where sex="f";
OUTPUT
| coach_id | name | age | sports | doa | pay | sex |
| 2 | nayo | 34 | karate | 1998-01-20 | 1260 | f |
| 4 | priyanka | 30 | football | 1998-01-01 | 1575 | f |
| 5 | pratibha | 35 | golf | 1998-01-12 | 3150 | f |
7. To display the coachnames, sports , pay and date of_app of all the
coaches whose name ends with “a”.
select name,sports,pay,doa from club where name like "%a";
OUTPUT
| name | sports | pay | doa |
| priyanka | football | 1575 | 1998-01-01 |
| pratibha | golf | 3150 | 1998-01-12 |
8.To display the coachname, sports ,age and pay of all the coaches
whose pay is in the range 2000-2500
select name,sports,age,pay from club where pay>=1000 and
pay<=2000;
OUTPUT
| name | sports | age | pay |
9.To display the details about all the coaches who are above 30 in
age and coach a sport starting with the letter “g”.
select * from club where age>30 and sports like "g%";
OUTPUT
| coach_id | name | age | sports | doa | pay | sex |
| 1 | prasun | 35 | golf | 1996-03-27 | 1050 | m |
| 5 | pratibha | 35 | golf | 1998-01-12 | 3150 | f |
11. To display the average Pay given for a coach for every sports
activity.
select avg(pay) from club group by sports;
OUTPUT
| avg(pay) |
| 1575.0000 |
| 2100.0000 |
| 1260.0000 |
| 2100.0000 |
12. To display the details about all the male coaches who joined after
15th February 1998.
select * from club where sex="m" and doa>"1998-02-15";
OUTPUT
| coach_id | name | age | sports | doa | pay | sex |
| 3 | shriram | 34 | squash | 1999-02-19 | 2100 | m |
13. To display the coach id , names and age of all the coaches who
coach neither Swimming nor golf
select coach_id,name,age from club where sports!="swimming" and
sports!="golf";
OUTPUT
| coach_id | name | age |
| 2 | nayo | 34 |
| 3 | shriram | 34 |
| 4 | priyanka | 30 |
14.To display the names of all the sports in the club which have more
than 2 coaches.
select sports from club group by sports having count(*)>1;
OUTPUT
| sports |
| golf |
15.To display the total salary given for male and female coaches in
the club.
select sum(pay) from club group by sex;
OUTPUT
| sum(pay) |
| 5985 |
| 3150 |