Adil Practicall Final
Adil Practicall Final
Adil Practicall Final
COMPUTER SCIENCE
SUB. CODE – 083
PRACTICAL FILE
NAME – ADIL HUSSAIN
CLASS – 12th__A__
Stream – PCM
CERTIFICATE
(Neeta Chauhan)
EXTERNAL SIGNATURE INTERNAL SIGNATURE
ACKNOWLEDGEMENT
-Adil Hussain
SL
NO. PRACTICAL NAME
4 Program to read the content of a file and display the total number of consonants, vowels and lower case
characters
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
Write SQL commands for the statements (i) to (V) and give outputs also:
Write SQL commands for the statements (i) to (V) and give outputs also:
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)
c=fact(n)
print("Factorial:",c)
print("1")
c=1
b=1
for i in range(a):
b+=c
print(b)
c,b=b,c
fibo(a)
for i in range(2,a):
c=a%i
if c==0:
break
else:
prime(pm)
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)
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)
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()
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=[]
for i in range(n):
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
alist[j+1]=alist[j]
j-=1
else:
alist[j+1]=key
return alist
alist=[]
for i in range(n):
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:
else:
stack.pop()
def display(stack):
if len(stack)==0:
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''')
if ch==1:
item=[emp_no,emp_name,emp_sal]
push(stack,item)
elif ch==2:
pop(stack)
elif ch==3:
display(stack)
else:
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
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.
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.
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.
A) Display data for all products whose Qty is between 170 and 370.
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.