KENDRIYA VIDYALAYA
CHENNEERKARA
COMPUTER SCIENCE PRACTICAL
(2024-25)
SUBMITTED TO: MRS.RAGENDU S.P
SUBMITTED BY: ABHISHEK AJEESH
CLASS: XI
INDEX
S.NO DATE TITLE SIGNATURE
1 Write a program to perform
addition, multiplication,
subtraction, division and mode
of two numbers
2 Write a python program to
calculate the simple interest
after reading details from user
3 Write a python program to find
whether the given number is
odd or even
4 Write a python program to find
the biggest of two numbers
5 Write a python program to find
whether the given number is
negative or not
6 Write a python program to
accept three numbers from the
user and sort them in ascending
order
7 Write a python program to
calculate percentage of marks
and grade based on marks.
8 Write a python program to read
two numbers and check whether
first number is divisible by
second
9 Write a python program to read
a number and check divisibility
by 3 and 5
10 Write a python program to read
the balance amount of a
customer and find out the
customer type based on the
following conditions
11 Write a python program to
display the multiplication table
of a given number
12 Write a python program to
display all the odd numbers
between 1 and 50 and also
calculate their sum
13 Write a menu driven program to
implement calculator
14 Write a python program to find
the factorial of a given number
15 Write a python program to
check whether the given
number is prime or not
16 Write a python program to
compute the greatest common
divisor and least common
multiple of two integers
17 Write a python program to
check whether the given
number is palindrome or not
18 Write a python program to print
the following pattern
*
**
***
****
*****
19 Write a python program to print
the following program
12345
1234
123
12
1
20 Write a python program to input
the value of x & n and print the
sum of the following series.
>x+(x^2)/2+(x^3)/3+….+(x^n)/n
>x+(x^2)/2!+(x^3)/3! +(x^n)/n!
21 Write a python program to find
the sum and average of all
elements in a list
22 Write a python program to find
out the sum of all even
numbers in the given list
23 Write a python program to
search for an element in a list
24 Write a python program to find
the largest element of a tuple
25 Write a python program to
input a list of numbers and
swap elements at the even
locations with the element al
the odd locations
26 Write a python program to count
the number of lowercase and
uppercase letters of given string
27 Write a python program to
convert the characters of a
given string to opposite case
28 Write a python program to
count the number of vowels in
a given string
29 Write a python program to
check whether the given string
is palindrome
30 Write a python program to
capitalize the first character of
each word in a given string
31 Write a python program to
find the number of
occurrences of a substring in
a given string
32 Write a python program to
display Fibonacci series of n
terms
a) Without using list
b) With list
33 Menu driven program to add,
delete and search elements in a
dictionary
34 To count the frequency of
numbers in a list using
dictionary
35 Menu driven program to find the
square root, power (4) and to
round of a number (by 3
Decimal places). (Use math
module functions)
36 Write a random number
generator that generates
random numbers
(i) Between 1 and 6
(simulates a dice).
(ii) Between 30 and 35
37 Use statistics module functions
to calculate mean, median and
mode of elements in a list
OUTPUT-1
Enter the first number: 4
Enter the second
number: 2 Sum of 4 and 2:
Difference of 4 and 2: 2
Product of 4 and 2: 8
Division of 4 and 2: 2.0
Remainder of 4 and 2: 0
PROGRAM-1
AIM: Write a python program to perform addition,
multiplication, subtraction, division and modes of
two numbers.
SOURCE CODE
a=int(input('Enter the first number:'))
b=int(input('Enter the second number:'))
print ('Sum of' ,a, 'and' ,b, ':, a+b)
print ('Difference of' ,a, 'and' ,b, ':' ,a-b)
print ('Product of' ,a, 'and' ,b, ':', a*b)
print ('Division of' ,a, 'and' ,b, ':', a/b)
print ('Remainder of' ,a, 'and' ,b, ':', a%b)
OUTPUT-2
Enter the principle amount:
20000 Enter the number of
years: 3 Enter interest rate: 3.5
Simple interest is 2100.0
PROGRAM-2
AIM: Write a python program to calculate simple
interest after reading details from users.
SOURCE CODE
pa= int (input ('Enter the principle
amount:')) n= int (input ('Enter the number
of years :')) r= float (input ('Enter interest
rate :'))
si=(pa*n*r)/100
print ('Simple interest is', si)
OUTPUT-3
Enter the number:
50 50 is even
Enter the number:
49 49 is odd
PROGRAM-3
AIM: Write a python program to find
whether the given number is odd or even.
SOURCE CODE
a=int (input ('Enter the number
:')) if a%2==0:
print (a, 'is even')
else:
print (a, 'is odd')
OUTPUT-4
Enter first number: 6
Enter second number:
3 6 is the bigger
number
PROGRAM-4
AIM: Write a python program to find the bigger of
two numbers.
SOURCE CODE
a=int (input ('Enter first number :'))
b=int (input ('Enter second number
:')) if a>b and b<a:
print (a, 'is the bigger
number') else:
print (b, 'is the bigger number')
OUTPUT-5
Enter the number:-30
-30 is negative
Enter the number:-30
-30 is negative
PROGRAM-5
AIM: Write a python program to find whether the
given number is negative or not.
SOURCE CODE
a=int (input ('Enter the number:'))
if a<0:
print (a, 'is negative')
else:
print (a, 'is positive')
OUTPUT-6
Enter number 1: 6
Enter number 2: 9
Enter number 3: 2
2<6<9
PROGRAM-6
AIM: Write a python program to accept three
numbers from user and sort them in ascending
order
SOURCE CODE
a = int (input ("Enter number 1:"))
b = int (input ("Enter number 2:"))
c = int (input ("Enter number
3:")) if a > b and a > c:
if b > c:
print (c, "<", b, "<", a)
elif c > b:
print (b, "<", c, "<", a)
elif b > a and b > c:
if a > c:
print (c, "<", a, "<", b)
elif c > a:
print (a, "<", c, "<", b)
else:
if a > b:
print (b, "<", a, "<", c)
elif b > a:
print (a, "<", b, "<", c)
OUTPUT-7
Enter the marks: 67
Grade D
PROGRAM-7
AIM: Write a python program to calculate percentage of marks and grade based on
marks:
i. Grade A if percentage >=90
ii. Grade B if 90>percentage>=80
iii. Grade C if 80>percentage>=70
iv. Grade D if 70>percentage>=60
v. Grade E if 60>percentage>=50
SOURCE CODE
a= int (input ('Enter the
marks:')) if a<=100 and a>=90:
print ('Grade A')
elif a<90 and a>=80:
print ('Grade B')
elif a<80 and a>=70:
print ('Grade C')
elif a<70 and a>=60:
print ('Grade D')
elif a<60 and a>=50:
print ('Grade E')
else:
print ('Fail')
OUTPUT-8
Enter the first number: 4
Enter the second
number: 2 4 is divisible by
2
PROGRAM-8
AIM: Write a python program to read two
numbers and check whether first number is
divisible by second.
SOURCE CODE
a=int (input ('Enter the first number :'))
b= int (input ('Enter the second number :'))
if a%b==0:
print (a, 'is divisible by'
,b) else:
print (a, 'is not divisible by' ,b)
OUTPUT-9
Enter the number:
15 15 is divisible by 3
15 is divisible by 5
15 is divisible by both 3 and 5
PROGRAM-9
AIM: Write a python program to read a number and
check divisibility by 3 and 5.
SOURCE CODE
a=int (input ('Enter the
number: ')) if a%3==0:
print (a, 'is divisible by
3') if a%5==0:
print (a, 'is divisible by
5') if a%3==0 and a%5==0:
print (a, 'is divisible by both 3 and 5')
OUTPUT-10
Enter balance amount:
5432 Platinum
PROGRAM-10
AIM: Write a python program to read the balance amount of a
customer and find out the customer type based on following
conditions:
i. Platinum if balance>=5000
ii. Gold if 5000>balance>=3000
iii. Silver if 3000>balance>=1000
iv. Balance not sufficient if balance<1000
SOURCE CODE
bal= int (input ('Enter balance
amount:')) if bal<5000 and bal>=3000:
print ('Gold')
elif bal<3000 and bal>=1000:
print ('Silver')
elif bal<1000:
print ('Balance not sufficient')
else:
print ('Platinum')
OUTPUT-11
Enter the number: 5
1X5=5
2 X 5 = 10
3 X 5 = 15
4 X 5 = 20
5 X 5 = 25
6 X 5 = 30
7 X 5 = 35
8 X 5 = 40
9 X 5 = 45
10 X 5 = 50
********
PROGRAM-11
AIM: Write a python program to display the
multiplication table of a given number.
SOURCE CODE
a=int (input ('Enter the number
:')) for i in range(a, a+1):
for j in range(1, 11):
print (j, 'X' ,i, '='
,i*j)
print ('********')
OUTPUT-12
Sum of odd numbers: 625
PROGRAM-12
AIM: Write a python program to display all the odd
numbers between 1 and 50 and also calculate their
sum.
SOURCE CODE
s=0
for i in range(1 ,50+1,
2): s=s + i
print ('Sum of odd numbers: ' ,s)
OUTPUT-13
1.Add
2.Subtract
3.Divide
4.Multiply
(1/2/3/4):4
Enter first no: 20
Enter second no: 2
20 x 2 = 40
do you want to continue(y/n):n
PROGRAM-13
AIM: Write a menu driven program to
implement calculator
SOURCE CODE
while True:
print("1.Add","\n2.Substract","\n3.Divide","\n4.Mult
ipl y")
print ("")
choice = int (input("(1/2/3/4):"))
a = int (input ("Enter first no:"))
b = int (input ("Enter second no:"))
if choice ==1:
print (a, "+" ,b, "=" ,a+b)
print ("")
elif choice ==2:
print (a, "-" ,b, "=" ,a-b)
print ("")
elif choice ==3:
print (a, "/" ,b, "="
,a/b) print ("")
elif choice ==4:
print (a, "x" ,b, "=" ,a*b)
print ("")
else:
print ("Invalid
Input") print ("")
ch= input("do you want to
continue(y/n):") if ch!='y':
break
OUTPUT-14
Enter a number: 3
Factorial of 3 is 6
PROGRAM-14
AIM: Write a python program to find the factorial of
a given number
SOURCE CODE
n=int (input ('Enter a number
:')) f=1
for i in range(1,n+1):
f=f*i
print('Factorial of' ,n, 'is' ,f)
OUTPUT-15
Enter the number:
5 5 is prime
PROGRAM-15
AIM: Write a python program to check the given
number is prime or not
SOURCE CODE
n=int (input ('Enter the number
:')) for i in range(2,(n//2)+1):
if n%i==0:
print (n, 'is not a prime number')
break
else:
print (n, 'is prime')
OUTPUT-16
Enter number1: 20
Enter number: 24
4
PROGRAM-16
AIM: Write a python program to compute the
greatest common divisor and least common
multiple of two integers.
SOURCE CODE
gcd =1
num1=int (input ('Enter number1
:')) num2=int (input ('Enter
number2 :')) if num1>num2:
temp
=num2 else:
temp =num1
for i in range (1,temp+1):
if num1%i==0 and
num2%i==0: gcd =i
print (gcd)
OUTPUT-17
Enter the no: 12321
12321 is palindrome
PROGRAM-17
AIM: Write a python program to check whether
the given number is palindrome or not
SOURCE CODE
n=int (input ("Enter the no :"))
num =n
rev =0
while
n>0:
d=n%10
rev = rev*10+d
n=n//10
if num - rev:
print (num, "is not palindrome")
else:
print (num, "is palindrome")
OUTPUT-18
Enter n: 5
**
***
****
*****
PROGRAM-18
AIM: Write a python program to print the following
pattern
*
**
***
****
*****
SOURCE CODE
n=int (input ('Enter n:'))
for i in range(1,n+1):
for j in range(1,i+1):
print ('*' ,end=' ')
OUTPUT-19
Enter n: 5
12345
1234
123
12
1
PROGRAM-19
AIM: Write a python program to print the following
pattern
12345
1234
123
12
1
SOURCE CODE
n=int (input ('Enter n :'))
for i in range(n,0,-1):
for j in range(1,i+1):
print (j, end=' ')
OUTPUT-20
Enter the value of x:
2 Enter the value of
n: 4
Sum = 10.666666666666666
PROGRAM-20
AIM: Write a python program to input the value of
x & n and print the sum of the following series
>x+(x^2)/2+(x^3)/3+….+(x^n)/n
>x+(x^2)/2!+(x^3)/3!. +(x^n)/n!
SOURCE CODE
x = int (input ("Enter the value of x:
")) n = int (input ("Enter the value of
n: ")) sum = 0
for i in range(1, n +
1) : term = x ** i /
sum += term
print ("Sum =" , sum)
OUTPUT-21
Enter the tuple (1, 2, 3,
4) Sum of elements 10
Average of elements
2.5
PROGRAM-21
AIM: Write a python program to find the sum and
average of all elements in the list
SOURCE CODE
t=eval (input ('Enter the tuple'))
sum =0
for i in t:
sum =sum + i
print ('Sum of elements' ,sum)
print ('Average of elements' ,sum/(len(t)))
OUTPUT-22
Enter the list [1, 2, 3, 4]
6
PROGRAM-22
AIM: Write a python program to find out the sum of
all even numbers in a given list
SOURCE CODE
l=eval (input ('Enter the list'))
s=0
for i in
range(0,len(l)): if
l[i]%2==0:
s = s+ l[i]
print (s)
OUTPUT-23
Enter the list [1, 5, 8, 7]
Enter the element to be
searched: 8 8 is present
Enter the list [1, 5, 8, 7]
Enter the element to be
searched: 2 2 not present
PROGRAM-23
AIM: Write a python program to search for a given
element in a list
SOURCE CODE
l=eval (input ('Enter the list'))
ele = int (input ('Enter the element to be
searched:')) for i in l:
if i==ele:
print (ele, 'is present')
break
else:
print (ele, 'not present')
OUTPUT-24
Enter the tuple (5, 6, 10,
4) Largest element is 10
PROGRAM-24
AIM: Write a python program to find the largest
element of a tuple
SOURCE CODE
t=eval (input ('Enter the tuple'))
m=t[0]
for i in
range(1,len(t)): if
m<t[i]:
m=t[i]
print ('Largest element is ' ,m)
OUTPUT-25
Enter list [8, 6, 4, 1]
List after swapping: [6, 8, 1, 4]
PROGRAM-25
AIM: Write a python program to input a list of
numbers and swap elements at the even locations
with the elements at the odd locations
SOURCE CODE
l=eval (input ('Enter list'))
for i in range(0, len(l) - 1,
2):
l[i], l[i + 1] = l[i + 1], l[i]
print ("List after swapping:", l)
OUTPUT-26
Enter the string HELLo
World No of lowercase
letters 5
No of upper case letter 5
PROGRAM-26
AIM: Write a python program to count the number
of uppercase and lowercase letters of given string
SOURCE CODE
st = input('Enter the string')
countl =0
countu =0
for i in st:
if i.islower():
countl+ =1
if i.isupper(): countu+=1
print ('No of lowercase letters' ,countl) print
('No of upper case letter' ,countu)
OUTPUT-27
Enter the string: HELLO world
hello WORLD
PROGRAM-27
AIM: Write a python program to convert the
characters of a given string to opposite case
SOURCE CODE
str =input('Enter the string:')
print (str.swapcase())
OUTPUT-28
Enter the string hello
world No of vowels 3
PROGRAM-28
AIM: Write a python program to count the number
of vowels in a given string
SOURCE CODE
st =input('Enter the
string') count = 0
for i in st:
i=i.lower()
if i=='a' or i=='e' or i=='i' or i=='o' or i=='u' :
count=count+1
print ("No of vowels" ,count)
OUTPUT-29
Enter the string madam
madam is palindrome
PROGRAM-29
AIM: Write a python program to check
whether the given string is palindrome
SOURCE CODE
s= input ("Enter the
string") st = s[: :-1]
if s==st :
print (s, "is
palindrome") else:
print (s, "not palindrome")
OUTPUT-30
Enter string: hello
Hello
PROGRAM-30
AIM: Write a python program to capitalize the first
character of each word in a given string
SOURCE CODE
St = input ('Enter string:')
Print (st.title())
OUTPUT-31
Enter string
computer 1
PROGRAM-31
AIM: Write a python program to find the number
of occurrences of a substring in a given string
SOURCE CODE
st = input ('enter
string') a =
st.count('pu')
print (a)
OUTPUT-32
Enter the number of terms: 8
Fibonacci Series: 0
13
Enter the number of elements:
5 [0, 1, 1, 2, 3]
PROGRAM-32
AIM: Write a python program to display Fibonacci
series of n terms
a) Without using a list
b) Using a list
SOURCE CODE
n=int (input ('Enter the number of terms :')) a , b =
0, 1
if n <= 0:
print ("Please enter a positive integer") elif n
== 1:
print (a)
else:
print ("Fibonacci Series: ", end="") for i in
range(n):
print (a, end=" ") a ,
b = b, a + b print ()
n=int (input ('Enter the number of elements:'))
l= [0,1]
for i in range(2,n):
l.append(l[i-1]+l[i-2])
print (l)
OUTPUT-33
Enter the no of elements 3
Enter the key 1
Enter the values 'unknown1'
Enter the key2
Enter the values 'unknown2'
Enter the key3
Enter the values 'unknown3'
{1: “‘unknown1’", 2: “‘unknown2’", 3: “‘unknown3’"}
Enter the key to add4
Enter the values 'unknown4'
New element added
{1: “‘unknown1’", 2: “‘unknown2’", 3: “‘unknown3’", 4: “‘unknown4’"}
Enter the key to delete3
Element deleted
{1: “‘unknown1’", 2: “‘unknown2’", 4: “‘unknown4’"}
Enter the key to search2
2: 'unknown2'
PROGRAM-33
AIM: Write a menu driven program to add,
delete and search elements in a dictionary
SOURCE CODE
d= {}
n=int (input ('Enter the no of
elements')) for i in range(n):
key = int (input ('Enter the
key')) values = input('Enter the
values') d[key]=values
print(d)
a=int (input ('Enter the key to add'))
d[a]=input('Enter the values')
print ('New element added')
print(d)
de = int (input ('Enter the key to delete'))
de=d.pop(de)
print ('Element deleted')
print(d)
for i in d:
s=int (input ('Enter the key to
search')) if s in d:
print (s, ':' ,d[s])
break
else:
print ('invalid key')
OUTPUT-34
{
"1": 1,
"2": 1,
"3": 1,
"4": 1
}
PROGRAM-34
AIM: Write a python program to count the
frequency of numbers in a list using dictionary
SOURCE CODE
import json
s='1 2 3 4 '
a=s.split()
d= {}
for i in a:
if i.isdigit():
key=i
if key not in d:
count = a.count(key)
d[key]=count
print (json.dumps(d, indent=1))
OUTPUT-35
Enter the number: 625
Square root is 25.0
Power by 4 is 152587890625.0
Round off by 3 digits are 625.0
PROGRAM-35
AIM: Write a menu driven program to find the
square root, power (4) and to round of a number
(by 3 decimal places)
SOURCE CODE
import math
n=float (input ('Enter the number:'))
print ('Square root is',math.sqrt(n))
print ('Power by 4 is',math.pow(n,4))
print ('Round off by 3 digits are' ,round(n,3))
OUTPUT-36
21645
30 34 33 30 35
PROGRAM-36
AIM: Write a random number generator that
generates random numbers
(i) Between 1 and 6 (simulates a dice).
(ii) Between 30 and 35
SOURCE CODE
import random
for i in range(5):
print (random.randint(1,6), end=" ")
print ()
import random
for i in range(5):
print (random.randint(30,35), end=" ") print ()
OUTPUT-37
Enter the list: [2, 4, 6, 5, 8, 7]
5.333333333333333
5.5
2
PROGRAM-37
AIM: write a python program to use statistics
module functions to calculate mean, median and
mode of elements in a list.
SOURCE CODE
list =eval (input ("Enter the
list:")) import statistics
print (statistics.mean(list))
print (statistics.median(list))
print (statistics.mode(list))
THANKYOU