You are on page 1of 48

SESSION 2022-2023

COMPUTER SCIENCE
SUB. CODE – 083
PRACTICAL FILE
NAME – ADIL HUSSAIN
CLASS – 12th__A__
Stream – PCM
CERTIFICATE

This is to certify that ADIL HUSSAIN


Roll no. : _________, of Class : ___12 A____
Session : __2022-2023___
has prepared the Practical file as per the prescribed
practical syllabus of
COMPUTER SCIENCE (083) CLASS 12TH (C.B.S.E.)
Under my supervision, I am completely satisfied by
the performance.
I wish him all the success in life.

(Neeta Chauhan)
EXTERNAL SIGNATURE INTERNAL SIGNATURE
ACKNOWLEDGEMENT

I would like to express my special


thanks of gratitude to my teacher Mrs.
Neeta Chauhan who gave me the
golden opportunity to do this
wonderful Practical file which also
helped me in doing a lot of Research
and I came to know about so many new
things I am really thankful to her.

-Adil Hussain
SL
NO. PRACTICAL NAME

1 Program to calculate factorial of a number

2 Program to generate Fibonacci series to the given nth term

3 Program to check whether the given number is prime or not

4 Program to read the content of a file and display the total number of consonants, vowels and lower case
characters

5 Program to search any word in a given string

6 Program to read and display a file line by line with each word separated by @

7 Program to create binary file containing Roll no. and name and search the Roll no. and display name

8 Program to create binary file to containing Roll no., name and marks and update marks of entered Roll no.

9 Program to read content of a file line by line and write it to another file except for the lines containing ‘a’ in it

10 Program containing a function that takes a sorted list and number as arguments and search for the number in
the list using binary search

11 Program to write and read data from a CSV file consisting item code, item name, quantity and price and search
for a particular item using item code
12 Program to sort a list using bubble sort

13 Program to sort a list using insertion sort

14 Program to guess a number game using random

15 Program to rotate the elements of a list (Palindrome)

16 Program to implement stack in python using list

17 Program to get HCF of two numbers

18 Program to check if a number is a happy number or not

19 SQL Connectivity: Create a Table

20 SQL Connectivity: Insert data in Table

SQL PRACTICAL LIST


1 Consider the following tables CABHUB and CUSTOMER.

Write SQL commands for the statements (i) to (V) and give outputs also:

2 Consider the following tables STORE and ITEM.

Write SQL commands for the statements (i) to (V) and give outputs also:

3 Consider the following tables STORE and ITEM.

Write SQL commands for the statements (i) to (V) and give outputs also:

4 Consider the following tables PRODUCT and CLIENT . Write SQL commands for the statements (i) to (V) and give
outputs also:

5 Consider the following tables STATIONARY and CONSUMER . Write SQL commands for the statements(i)to(V)
and give outputs
1.Program to calculate factorial of a number
def fact(a):

if a==1:

return a

else:

return a * fact(a-1)

n=int(input ("Enter any number to get a factorial of:"))

c=fact(n)

print("Factorial:",c)

2.Program to generate Fibonacci series to the given


nth term
def fibo(a):
print("1")

print("1")

c=1

b=1

for i in range(a):

b+=c

print(b)

c,b=b,c

a=int(input("Enter the number of elements you need in fibonacci series"))

fibo(a)

3.Program to check whether the given number is


prime or not
def prime(a):

for i in range(2,a):
c=a%i

if c==0:

print(a,"is not a prime number")

break

else:

print(a,"is a prime number")

pm=int(input("Enter a number to check is it is a prime number"))

prime(pm)

4.Program to read the content of a file and display the total


number of consonants, vowels and lower case characters

f=open("adilpr6n.txt","r")
data=f.read()
count_vowels=0
count_consonants=0
count_lower=0
print(data)
for i in data:
if i.islower():
count_lower+=1
elif i in "aeiouAEIOU":
count_vowels+=1
elif i in "qwrtypasdfghjklzxcvbnmQWRTYPASDFGHJKLZXCVBNM":
count_consonants+=1
else:
None
print("vowels:",count_vowels)
print("consonants:",count_consonants)
print("lower:",count_lower)

5.Program to search any word in a given string

def search(a,src):
if src in a:
print(src,"is present in",'"',a,'"')
elif src not in a:
print(src,"is not present in",'"',a,'"')
a=str(input("Enter the string you want to search from"))
b=str(input("Enter the word you want to search"))
search(a,b)

6.Program to read and display a file line by line with each


word separated by @

f=open("adilpr6.txt",”r+”)
fr=f.read()
print("Original Text:",fr)
list1=fr.split()
print("Changed Text:", end="")
for i in list1:
print(i+"@",end="")
f.close()

7.Program to create binary file containing Roll no. and


name and search the Roll no. and display name
import pickle
def rolln():
f=open("Sturollpr7.dat","wb+")
n=int(input("Enter the number of records you want"))
dict1={}
for i in range(n):
dict1['Roll no']=int(input("Enter roll no"))
dict1['Student Name']=str(input("Enter Name"))
pickle.dump(dict1,f)
f.flush()
f.close()
fb=open("Sturollpr7.dat","rb+")
src=int(input("Enter the roll no you want to search"))
r={}
try:
while True:
r=pickle.load(fb)
if r["Roll no"]==src:
print("record of",src,"is",r)
break
except EOFError:
print("There is no such record")
fb.close()
rolln()

8.Program to create binary file to containing Roll no., name


and marks and update marks of entered Roll no.

import pickle

def entry(b):
f = open('Marks.txt', 'wb')
t = int(input('\nHow many entries do you want to make ? '))
l=[]
for key in b:
l+=[key]
for i in range(t):
k = input('\nRoll no. = ')
if k in l:
ask=input('Roll no. already exists. Do you want to overwrite it ? (Y/N) : ')
if ask in ['y','Y']:
v1 = input('Name = ')
v2 = input('Marks = ')
else:
v1,v2=b[k]
else:
v1 = input('Name = ')
v2 = input('Marks = ')
print('-' * 80)
b[k] = [v1, v2]
pickle.dump(b, f)
f.close()
print('\nEntries made successfully.\n', '_' * 80)

def search(b,s):
try:
for i in range(2):
print(b[s][i])
except:
print('\nRoll no. not found !\n')
print('-' * 80)

def update(b,s):
try:
m = input('Marks = ')
b[s][1] = m
f = open('Marks.txt', 'wb')
pickle.dump(b, f)
f.close()
print('\nMarks Updated Successfully !\n')
except:
print('\nRoll no. not found !\n')
print('_' * 80)

ch=1
print('\nChoose :\n\n1)Make entries\n2)Search Roll no.\n3)Update
marks\n4)Exit')
while ch in (1,2,3):
ch = int(input('\nEnter your choice : '))
try:
if ch in [1,2,3]:
f = open('Marks.txt', 'rb')
b = pickle.load(f)
f.close()
if ch == 1:
entry(b)
elif ch == 2:
s = input('\nRoll no. = ')
search(b,s)
elif ch == 3:
s = input('\nRoll no. = ')
update(b,s)
except:
b={}
if ch in [2,3]:
print('File is empty!Enter some data first.')
entry(b)
9.Program to read content of a file line by line and write it
to another file except for the lines containing ‘a’ in it

f=open('ADILPR9.TXT','r')
f2=open('2ADILPR9.TXT','w')
lines=f.readlines()
for i in lines:
if "a" not in i:
f2.write(i)
print("Program succesfully executed")
f.close()
f2.close()
10. Program containing a function that takes a sorted list
and number as arguments and search for the number in
the list using binary search

def bsearch(l,s):
start,end = 0,len(l)-1
while start <= end:
mid = (start+end)//2
if s == l[mid]:
print('\nFound at index',mid)
break
elif s > l[mid]:
start = mid+1
else:
end = mid-1
else:
print('\nNot found')
l = eval(input('\nEnter the list : '))
l.sort()
s = int(input('\nSearch : '))
bsearch(l,s)
print('_'*80)
11.Program to write and read data from a CSV file
consisting item code, item name, quantity and price and
search for a particular item using item code

import csv

def entry():
l = []
f = open('item.csv','w',newline='')
w = csv.writer(f)
w.writerow(['ITEM CODE','ITEM NAME','QUANTITY','PRICE'])
t = int(input('\nHow many entries do you want to make ? '))
for i in range(t):
c = input('\nItem Code = ')
n = input('Item Name = ')
q = input('Quantity = ')
p = input('Price = ')
l.append([c,n,q,p])
print('-' * 80)
w.writerows(l)
f.close()
print('\nEnteries made successfully\n')

def search(r,s):
for i in r:
if i[0] == s:
print('\n',i)
break
else:
print('\nItem not found !\n')

ch=1
print('\nChoose :\n\n1)Make entries\n2)Search Item\n3)Exit')
while ch in (1,2):
try:
ch = int(input('\nEnter your choice : '))
f = open('item.csv', 'r')
r = csv.reader(f)
if ch == 1:
entry()
elif ch == 2:
s = input('\nEnter Item Code : ')
search(r, s)
f.close()
print('_' * 80)
except:
if ch == 2:
print('\nFile is empty. Make some entries first.')
entry()
12.Program to sort a list using bubble sort
def bsort(list1):

n=len(list1)

for i in range(n):

for j in range(n-i-1):

if list1[j]>list1[j+1]:

list1[j],list1[j+1]=list1[j+1],list1[j]

return list1

alist=[]

n=int(input("Enter the number of elements you need in list"))

for i in range(n):

a=eval(input("Enter the element you want to enter"))

alist.append(a)

blist=bsort(alist)

print("Sorted List=",blist)
13.Program to sort a list using insertion sort
def insort(alist):

n=len(alist)

for b in range(1,n):

key=alist[b]

j=b-1

while j>=0 and key<alist[j]:

alist[j+1]=alist[j]

j-=1

else:

alist[j+1]=key

return alist

alist=[]

n=int(input("Enter the number of elements you need in list"))

for i in range(n):

a=eval(input("Enter the element you want to enter"))

alist.append(a)

blist=insort(alist)

print("Sorted Listed",blist)
14. Program to guess a number game using random

import random
print ("Guess a number , you will get 3 chances, ")
n=random.randrange(1,11)
for i in range (1,5):
if i!=4:
n2=int(input('guess the number'))
if n2==n:
print('you entered the right guess ',n)

i=5
break
if n2!=n:
print('try again')
if i==4:
print('you ended all chances\nright guess is ',n)
15.Program to rotate the elements of a list
(Palindrome)
def reverse(l):
r = []
for i in range(-1,-len(l)-1,-1):
r += [l[i]]
return r
l=eval(input('Enter list : '))
print('Reversed list :',reverse(l))
16. Program to implement stack in python
using list
def push(stack,item):

stack.append(item)

def pop(stack):

if len(stack)==0:

print('\nUNDERFLOW. Stack is empty!')

else:

stack.pop()

def display(stack):

if len(stack)==0:

print('\nUNDERFLOW. Stack is empty!')

else:

for i in stack:

print(i)

stack=[]

ch=1

while ch in [1,2,3]:

print('''\n*********STACK MENU*********

1) PUSH
2) POP

3) DISPLAY

4) EXIT''')

ch=int(input('\nEnter your choice : '))

if ch==1:

emp_no=int(input('\nEnter employee number : '))

emp_name=input('Enter employee name : ')

emp_sal=int(input('Enter employee sal : '))

item=[emp_no,emp_name,emp_sal]

push(stack,item)

elif ch==2:

pop(stack)

elif ch==3:

display(stack)

else:

print('\nYou choOse to exit the program.')


17. Program to get HCF of two numbers
a=int(input("enter first number"))

b=int(input("enter second number"))

while b!=0:

a,b=b,a%b

print("HCF=",a)
18. Program to check if a number is a happy number or not
def chappy(x):
for j in range(20):
sum1=0
x=str(x)
alist=list(x)
n=len(alist)
for i in range(n):
sum1=sum1+((eval(alist[i]))**2)
x=sum1
print("SUM",j,"is",sum1)
if sum1==1:
print("This number is a Happy number")
break
else:
print("This number is not a Happy number")
n=int(input("Enter number to check if it is happy number or not"))
chappy(n)
19. SQL Connectivity: Create a Table

import mysql.connector as sqlc


con=sqlc.connect(host='localhost',user='root',password='1234',database='proj
ect')
cur=con.cursor()
cur.execute("Create table loginn (username varchar(50), password
varchar(50));")
print("Table is created successfully!!!")
con.commit()
con.close()
20. SQL Connectivity: Insert data in Table
import mysql.connector as sqlc
con=sqlc.connect(host='localhost',user='root',password='1234',database='proj
ect')
cur=con.cursor()
fname=input('Enter the name of your file')
dos=input('Enter date of submission: in YYYY/MM/DD')
cur.execute('Insert into adil value("'+fname+'", "'+dos+'");')
con.commit()
SQL PROGRAMS

Q1. Given the following for a database LIBRARY:

TABLE : BOOKS
BOOK_I BOOK_NAM AUTHOR_NAM PUBLISHER PRIC TYPE QTY
D E E S E .
C0001 Fast cook Lata kapoor EPB 355 Cooker 5
y
F0001 The tears William First Publ. 650 Fiction 20
Hopkins
T0001 My first Brian & Brooke EPB 350 Text 10
C++
T0002 C++ brain A.W. Rossaine TDH 350 Text 15
works
F0002 Thunderbolt Anna Roberts First Publ. 750 fiction 50
s

TABLE : ISSUED
BOOK_ID QUANTITY_ISSUED
T0001 4
C0001 5
F0001 2
(a) To show book name, author name and price of books
of first publ. publishers.

(b)To list the names form books of text type.

(c)To display the names and price from books in


ascending order of their price.
(d) To increase the price of all books of EPB Publishers by
50.

(e)To display the book_id, book_name, and


quantity_issued for all books which have been issued.

(f)To insert a new row in the table issued having the


following data : “F0003”,1.
Q2. consider the following tables Product and
Client. write SQL commands for the statements (i) to
(iii) and give outputs for SQL queries (iv) to (vi)
TABLE : PRODUCT
P_ID PRODUCT_NAME MANUFACTURE PRICE
TP01 Talcum powder LAK 40
FW05 Face wash ABC 45
BS01 Bath soap ABC 55
SH06 Shampoo XYZ 120
FW12 Face wash XYZ 95

TABLE : CLIENT
C_ID CLIENT NAME CITY P_ID
01 Cosmetic shop Delhi FW05
06 Total health Mumbai BS01
12 Live life Delhi SH06
15 Pretty woman Delhi FW12
16 Dreams Bengaluru TP01
i) To display the details of those clients whose city is
delhi.

ii) To display the details of products whose price is in the


range of 50 to 100(both values included).

iii) To display the details of those products whose name


ends with ‘wash’.
iv) select distinct city from client;

v) select product_name, price * 4 from product;


Q3. Consider the following dept and workers
tables. Write SQL queries for (i) and (iv) find
outputs for SQL.

TABLE : DEPT
DCODE DEPARTMENT CITY
D01 MEDIA DELHI
D02 MARKETING DELHI
D03 INFRASTRUCTURE MUMBAI
D05 FINANCE KOLKATA
D04 HUMAN RESOURCES MUMBAI

TABLE : WORKER
WNO NAME DOJ DOB GENDER DCODE
1001 GEORGE K 2013-09- 1991-09- M D01
02 01
1002 RYMA SEN 2012-12- 1990-12- F D03
11 15
1003 MOHITESH 2013-02- 1987-09- M D05
03 04
1007 ANIL JHA 2014-01- 1984-10- M D04
17 19
1004 MANILA SAHAI 2012-12- 1986-11- F D01
09 14
1005 R SAHAY 2013-11- 1987-03- M D02
18 31
1006 JAYA PRIYA 2014-06- 1985-06- F D05
09 23
(i) To display Wno, name, gender, from the table
WORKER in descending order of Wno.

(ii)To display the name of all the female workers from


the table worker.

(iii)To count and display male workers who have joined


after “1986-01-01”.
(iv)SELECT DISTINCT DEPARTMENT FROM DEPT;

(v)SELECT MAX(DOJ), MIN(DOB) FROM WORKER;


4) Write the SQL commands for following queries.
Sno Pname Sname Qty Price City
S1 Bread Britannia 150 8.00 Delhi
S2 Cake Britannia 250 20.00 Mumbai
S3 Coffee Nescafe 170 45.00 Mumbai
S4 Chocolate Amul 380 10.00 Delhi
S5 Sauce Kissan 470 36.00 Jaipur

A) Display data for all products whose Qty is between 170 and 370.

B) Display data for all products sorted by their quantity.

C) Find all the products that have no supplier.


D) Give Sname, Pname, Price for all the product whose name starts with “c”.

E) To list Sname, Pname, Price for all the products whose quantity is <200.
5) Consider the following tables: company and
model

TABLE: COMPANY
Comp_id Compname CompHO Contactperson
1 Titan Okhla C.B.Ajit
2 Ajanta Najafgarh R.Mehta
3 Maxima Shahdara B.Kohli
4 Seiko Okhla R.Chadha
5 Ricoh Shahdara J.Kishore

TABLE: MODEL
Model_id Comp_id Cost DateofManufacture
T020 1 2000 2010-05-12
M032 4 7000 2009-04-15
M059 2 800 2009-09-23
A167 3 1200 2011-01-12
T024 1 1300 2009-10-14
a) To display details of all models in the model table in
ascending order of date of manufacture.
b) To display details of those models manufactured in
2011 and whose cost is below 2000.

c) To decrease the cost of all model in the model table


by 15%.

d) select count (distinct CompHO) from company;

e) select compname,”Mr.”,contactperson from company


where compname like “%a”;

You might also like