Professional Documents
Culture Documents
COMPUTER SCIENCE
SUB. CODE - 083
TERM-I PRACTICAL FILE
NAME:-_____________________________________
STREAM:-____________________________________
Session :2021-22
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:-
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:-
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:-
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")