You are on page 1of 18

ST.

JOSEPH’S CONVENT HIGH SCHOOL


(C.B.S.E) CHITTARANJAN
SESSION:-2021-22

COMPUTER SCIENCE
SUB. CODE - 083
TERM-I PRACTICAL FILE

NAME:-_____________________________________

STREAM:-____________________________________

BOARD ROLL NO:-_____________________________


CERTIFICATE

This is to certify that ,


Roll No:________________________of Class:XII,

Session :2021-22

has prepared the Practical file as per the


prescribed Practical Syllabus of Term-I
COMPUTER SCIENCE(083)
Class XII (C.B.S.E.)

under my supervision, I am completely satisfied


by the performance.
I wish him/her all the success in life.

Principal’s Subject Teacher’s


Signature Signature

External’s Signature
TERM-I INDEX PAGE
PYTHON PROGRAMS
SL PAGE TEACHER’S
Practical Name
No NO. SIGNATURE
Write a program to check a number whether it is
1
palindrome or not.
Write a program to display ASCII code of a
2
character and vice versa.
Write a program that adds individual elements of
3 list 2 and 3 into 1. Resultant list should be in
order of elements of list 3, list1,list 2.
Write a program that find an elements
4
index/position in a tuple Without using index( ).
Write a program that checks for presence of a
5 value inside a dictionary and prints its keys with
ignore case.
Write a program using function that receives two
6 number and return the result of all the arithmetic
operations(+,-,*,/,%) .
Write a menu driven program to calculate :
7 Area of circle [A=πr2] Area of square [A=a*a] Area of
rectangle [A=l*b]
Write a program to count the no. of uppercase,
8 lowercase, alphabets, digits in given
string/sentence.
9 Write a program to count number of words in a file.
Program to read and display file content line by
10
line with each word separated by “#”
Write a program to copy all the lines that not
11 contain the character `a' in a file and write it to
another file.
Program to read the content of file and display the
12 total number of consonants, uppercase, vowels and
lower case characters‟
Program to create binary file to store Rollno and
13 Name, Search any Rollno and display name if
Rollno found otherwise “Rollno not found”
Program to create binary file to store Rollno, Name
14
and Marks and update marks of entered Rollno
Write a program to perform read and write
15
operation with .csv file.
Program 1:- Write a program to check a number whether it is
palindrome or not.

Source Code:-

num=int(input("Enter a number : "))


n=num
res=0
while num>0:
rem=num%10
res=rem+res*10
num=num//10
if res==n:
print(n," is Palindrome")
else:
print(n, " is not Palindrome")
Program 2:- Write a program to display ASCII code of a character and
vice versa.

Source Code:-

var=True
while var:
choice=int(input("Press-1 to find the ordinal value of a
character \nPress-2 to find a character of a value\n"))
if choice==1:
ch=input("Enter a character : ")
print(ord(ch))
elif choice==2:
val=int(input("Enter an integer value: "))
print(chr(val))
else:
print("You entered wrong choice")
print("Do you want to continue? Y/N")
option=input()
if option=='y' or option=='Y':
var=True
else:
var=False
Program 3 :- Write a program that adds individual elements of list 2
and 3 into 1. Resultant list should be in order of elements of list 3,
list1,list 2.

Source Code:-

l1=[1,2,3]
l2=[4,5,6]
l3=[7,8,9]
print("List1:-",l1)
print("List2:-",l2)
print("List3:-",l3)
l3.extend(l1)
l3.extend(l2)
print("after adding elements of two list :-",l3)
Program 4 :- Write a program that find an elements index/position in
a tuple Without using index( ).

Source Code:-

tuple1 = ('a', 'p', 'p', 'l', 'e',)


char = input("Enter a single letter without quotes: ")
if char in tuple1:
count=0
for a in tuple1:
if a != char:
count += 1
else:
break
print(char, "is at index", count, "in", tuple1)
else:
print(char, "is NOT in", tuple1)
Program 5 :- Write a program that checks for presence of a value
inside a dictionary and prints its keys with ignore case.

Source Code:-

info = {'Riya':'CSc.','Mark':'Eco','Ishpreet':'Eng','Kamaal':'Env.Sc'}
inp=input ("Enter value to be searched for :")
for a in info:
if(info[a].upper()==inp.upper()):
print("The key of given value is", a)
break
else:
print("Given value does not exist in dictionary")
Program 6 :- Write a program using function that receives two number
and return the result of all the arithmetic operations(+,-,*,/,%) .

Source Code:-

result = 0
val1 = float(input("Enter the first value :"))
val2 = float(input("Enter the second value :"))
op = input("Enter any one of the operator (+,-,*,/,//,%)")
if op == "+":
result = val1 + val2
elif op == "-":
result = val1 - val2
elif op == "*":
result = val1 * val2
elif op == "/":
if val2 == 0:
print("Please enter a value other than 0")
else:
result = val1 / val2
elif op == "//":
result = val1 // val
else:
result = val1 % val2
print("The result is :",result)
Program 7 :- Write a menu driven program to calculate :
Area of circle [A=πr2] Area of square [A=a*a] Area of rectangle [A=l*b]
Source Code:-
def circle(r):
return 3.14*r*r
def square(a):
return a*a
def ractangle(l,b):
return l*b

while 1:
print("="*40)
print("********Main Menu*******")
print("1 for calculate Area of circle [A=πr2]")
print("2 for calculate Area of square [A=a*a]")
print("3 for calculate Area of rectangle [A=l*b]")
print("="*40)
n=int(input("Enter your Choice(1,2,3): "))
if n==1:
r=float(input("Enter the radius:-"))
area=circle(r)
print("Area of Circle:=",area)
elif n==2:
s=float(input("Enter the side length:-"))
area=square(s)
print("Area of square:=",area)
elif n==3:
l=float(input("Enter the value of l:-"))
b=float(input("Enter the value of b:-"))
area=ractangle(l,b)
print("Area of ractangle:=",area)
else:
print("Your choice is Wrong")
ch=input("Y/N : ")
if ch=='n' or ch=='N':
break
Program 8 :- Write a menu driven program to count the no. of
uppercase, lowercase, alphabets, digits in given string/sentence.

Source Code:-

line=input ("Enter a line :")


lowercount=uppercount=0
digitcount=alphacount=0
for a in line :
if a.islower():
lowercount += 1
elif a.isupper():
uppercount += 1
elif a.isdigit():
digitcount += 1
if a.isalpha():
alphacount +=1
print("Number of uppercase letters:", uppercount)
print("Number of lowercase letters:", lowercount)
print("Number of alphabets:", alphacount)
print("Number of digits :", digitcount)
Program 9 :- Write a program to count number of words in a file.

Source Code:-

fin=open("file1.txt",'r')
str=fin.read()
L=str.split()
count_words=0
print("Content of file:-",str)
for i in L:
count_words=count_words+1
print("Total no.of Words:-",count_words)
Program 10: Program to read and display file content line by line
with each word separated by “ # ”

Source Code:-

f = open("data.txt")
for line in f:
words = line.split()
for w in words:
print(w+'#',end='')
print()
f.close()
Program 11: Write a program to copy all the lines that not
contain the character `a' in a file and write it to another file.
Source Code:-

f1 = open("file2.txt")
f2 = open("file2copy.txt","w")

for line in f1:


if 'a' not in line:
f2.write(line)
print("## File Copied Successfully! ##")
f1.close()
f2.close()
Program 12: Program to read the content of file and display the
total number of consonants, uppercase, vowels and lower case
characters.
Source Code : -
f = open("file1.txt")
v,c,u,l,o=0,0,0,0,0
data = f.read()
vowels=['a','e','i','o','u']
for ch in data:
if ch.isalpha():
if ch.lower() in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
elif ch!=' ' and ch!='\n':
o+=1
print("Total Vowels in file:-",v)
print("Total Consonants in file n :",c)
print("Total Capital letters in file :",u)
print("Total Small letters in file :",l)
print("Total Other than letters :",o)
f.close()
Program 13: Program to create binary file to store Rollno and Name,
Search any Rollno and display name if Rollno found otherwise “Rollno
not found”
Source Code:-
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
Program 14: Program to create binary file to store Rollno,Name and
Marks and update marks of entered Rollno.
Source Code:-
import pickle
student=[]
f=open('student.dat','wb')
ans='y'
while ans.lower()=='y':
roll = int(input("Enter Roll Number :"))
name = input("Enter Name :")
student.append([roll,name])
ans=input("Add More ?(Y)")
pickle.dump(student,f)
f.close()
f=open('student.dat','rb')
student=[]
while True:
try:
student = pickle.load(f)
except EOFError:
break
ans='y'
while ans.lower()=='y':
found=False
r = int(input("Enter Roll number to search :"))
for s in student:
if s[0]==r:
print("## Name is :",s[1], " ##")
found=True
break
if not found:
print("####Sorry! Roll number not found ####")
ans=input("Search more ?(Y) :")
f.close()
Program 15 :- Write a program to perform read and write operation with
.csv file.
Source Code:-
import csv
with open('myfile.csv',mode='a') as csvfile:
mywriter = csv.writer(csvfile,delimiter=',')
ans='y'
while ans.lower()=='y':
eno=int(input("Enter Employee Number:- "))
name=input("Enter Employee Name:- ")
salary=int(input("Enter Employee Salary:-"))
mywriter.writerow([eno,name,salary])
print("## Data Saved... ##")
ans=input("Add More ?")
ans='y'
with open('myfile.csv',mode='r') as csvfile:
myreader = csv.reader(csvfile,delimiter=',')
while ans=='y':
found=False
e = int(input("Enter Employee Number to search :"))
for row in myreader:
if len(row)!=0:
if int(row[0])==e:
print("============================")
print("NAME :",row[1])
print("SALARY :",row[2])
found=True
break
if not found:
print("==========================")
print(" EMPNO NOT FOUND")
print("==========================")
ans = input("Search More ? (Y)")

You might also like