0% found this document useful (0 votes)
11 views24 pages

File 2

Uploaded by

darshanabinavrk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views24 pages

File 2

Uploaded by

darshanabinavrk
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

CHENNAI PUBLIC SCHOOL

TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124


RECORD PROGRAMS
PROGRAM 8 : CHECKING ARMSTRONG NUMBER

AIM

To write a program that accepts a number and checks whether the given number is Armstrong or not..

ALGORITHM

STEP 1 : Start the process


STEP 2 : Get the number (num)
STEP 3 : Assign f=num and sum=0
STEP 4 : Repeat steps 5, 6 and 7 while f>0
STEP 5 : a=f%10
STEP 6 : f=int(f/10)
STEP 7 : sum=sum+(a**3)
STEP 8 : if sum== num ,print num “is an Armstrong number”,goto step 10
otherwise goto step 9
STEP 9 : print num “is not an Armstrong number”
STEP 10 : Stop the process

CODE

num=int(input ('enter 3-digit number: '))


f=num
sum=0
while(f>0):
a=f%10
f=int(f/10)
sum=sum+(a**3)
if (sum==num):
print (num,'is an armstrong number.')
else:
print(num,'is not an armstrong number.')

OUTPUT

enter 3-digit number: 456


456 is not an armstrong number.

enter 3-digit number: 153


153 is an armstrong number.

PROGRAM 9 : CHECHING IF NUMBER IS PALINDROME

AIM

To write a program that accepts a number and checks whether the given number is palindrome or not.

ALGORITHM

Page 1 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
STEP 1: Start the process
STEP 2 : Get the number (orig)
STEP 3 : Assign num=orig and rev=0
STEP 4 : Repeat steps 5, 6 and 7 while num>0 else goto step 8
STEP 5 : digit=num%10
STEP 6 : rev=rev*10+digit
STEP 7 : num=int(num/10)
STEP 8 : if orig== rev ,print “palindrome”,goto step 10
Otherwise goto step 9
STEP 9 : print “not a aplindrome”
STEP 10 : Stop the process

CODE

orig=int(input('enter a number'))
num=orig
rev=0
while num>0:
digit=num%10
rev=rev*10+digit
num=int(num/10)
if orig==rev:
print('palindrome')
else:
print('not a palindrome')

OUTPUT

enter a number875
not a palindrome

enter a number12321
palindrome

PROGRAM 10: SUM OF SERIES

AIM
Write a program to find and display the sum of the given series till n terms, where n is defined by the user.

ALGORITHM

Page 2 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS

STEP 1 : Start the process


STEP 2 : Accept the nth value from user
STEP 3 : Repeat step 4 for 1 to n+1, otherwise go to step 5
STEP 4 : Compute Sum = sum+1/(pow(2,i))
STEP 5 : Print the sum
STEP 6 : End the process

FLOW CHART
START

import math
ACCEPT N

SUM = 0 , I = 1

NO
Is I <= n

YES

COMPUTE
SUM = SUM+1/(POW(2,I))

DISPLAY SUM

CODE : STOP

import math
sum=0
n=int(input(" Enter the number : " ))
for i in range(1,n+1):
print('1/',pow(2,i),'+',end='')
sum=sum+1/(pow(2,i))
print("0 \n The sum of the series is : ",sum)

OUTPUT

Page 3 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
Enter the number : 7
1/ 2 +1/ 4 +1/ 8 +1/ 16 +1/ 32 +1/ 64 +1/ 128 +0
The sum of the series is : 0.9921875

PROGRAM 11 :PRINT A NUMBER PATTERN

AIM

Write a program that accepts N and displays a numeric pattern for N terms

ALGORITHM

STEP 1 : Start the process


STEP 2 : Accept the value of N
STEP 3 : Repeat i in steps 4 for N times, otherwise got to step 7
STEP 4 : Repeat j in step 5 for I times, otherwise got to step 6 for next value of I
STEP 5 : Display I; in same line
STEP 6 : Display blank or newline

Page 4 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
STEP 7 : End the process

FLOW CHART
START

Accept N

I = J = 1

Is I <N+1 NO

YES

Is J < I NO

YES
Print(I,end=’’)

Print(’’)

STOP

CODE

N = int(input('Enter the number of rows'))

for i in range(N+1):
for j in range(i):
print( i, end=' ')
print('')

OUTPUT

Enter the number of rows7

1
22
333

Page 5 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
4444
55555
666666
7777777

PROGRAM 12 : STRING OPERATIONS - 1

AIM

Write a program to count the lines, words, and characters in a user defined string.

ALGORITHM

STEP 1 : Start the process


STEP 2 : Initialize two string variables mainstr and s as null
STEP 3 : Initialize three numeric variables char, word and line to 0, to store the count of
the number of characters, words and lines in the given string
STEP 4 : Accept string value from user and store it into mainstr variable until user
decides not to store any more lines.
STEP 5 : Using FOR loop traverse through each character and count and store the
count in char
STEP 6 : Using FOR loop , for each space occurring using split(), count the number of
words and store it in word.
STEP 7 : Using FOR loop, for each line ending with NEWLINE count and store the
value in line.
STEP 8 : Display the original string, and the count of char, word and line
STEP 9 : Stop the process

CODE

mainstr=s=''
while True:
s=input(" Enter a line : ")
mainstr=mainstr+s+'\n'
ch=input("\n\t Press y to enter more lines other wise press N : ")
if ch in 'Nn':
break

char=word=line=0

for i in mainstr:
char=char + 1
if i=='\n':
line=line+1

for i in mainstr.split():
word=word+1

print( '\n \t The original string is : \n', mainstr)

Page 6 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
print( '\n \t The total number of characters in the given string is ', char)
print( '\n \t The total number of words in the given string is ', word)
print( '\n \t The total number of lines in the given string is ', line)

OUTPUT

Enter a line : A bad workman always blames his tools.

Press y to enter more lines other wise press N : y


Enter a line : All that glitters is not gold

Press y to enter more lines other wise press N : y


Enter a line : A picture is worth a thousand words.

Press y to enter more lines other wise press N : n

The original string is :


A bad workman always blames his tools.
All that glitters is not gold
A picture is worth a thousand words.

The total number of characters in the given string is 106

The total number of words in the given string is 20

The total number of lines in the given string is 3

PROGRAM 13 : STRING OPERATIONS - 2

AIM

Write a program to count the number of vowels, consonents, and digits in a user defined multiline string.

ALGORITHM

STEP 1 : Start the process


STEP 2 : Initialize two string variables mainstr and s as null
STEP 3 : Initialize three numeric variables vow, con and dig to 0, to store the count of
the number of vowels, consonents and digits in the given string
STEP 4 : Accept string value from user and store it into mainstr variable until user
decides not to store any more lines.
STEP 5 : for i in mainstr:
if i.isalnum():
if i.isalpha():
if i in 'AEIOUaeiou':
vow=vow+1
else:
con=con+1

Page 7 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
else:
dig=dig+1
else:
continue
STEP 6 : Display the original string, and the count of vowels, consonants and digits
STEP 7 : Stop the process

FLOW CHART

CODE

mainstr=s=''
while True:
s=input(" Enter a line : ")
mainstr=mainstr+s+'\n'
ch=input("\n\t Press y to enter more lines other wise press N : ")
if ch in 'Nn':
break

vow=con=dig=0

for i in mainstr:
if i.isalnum():
if i.isalpha():
if i in 'AEIOUaeiou':
vow=vow+1
else:
con=con+1
else:
dig=dig+1
else:
continue

print( '\n \t The original string is : \n', mainstr)

print( '\n \t The total number of vowels in the given string is ', vow)
print( '\n \t The total number of consonents in the given string is ', con)
print( '\n \t The total number of digits in the given string is ', dig)

OUTPUT

Enter a line : Scholars estimate that the first successful expansion of the Homo sapiens range beyond Africa
and across the Arabian Peninsula occurred from as early as 80,000 years ago to as late as 40,000 years ago,
although there may have been prior unsuccessful emigrations. Some of their descendants extended the
human range ever further in each generation, spreading into each habitable land they encountered. One
human channel was along the warm and productive coastal lands of the Persian Gulf and northern Indian
Ocean. Eventually, various bands entered India between 75,000 years ago and 35,000 years ago

Page 8 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
Press y to enter more lines other wise press N : n

The original string is :


Scholars estimate that the first successful expansion of the Homo sapiens range beyond Africa and across
the Arabian Peninsula occurred from as early as 80,000 years ago to as late as 40,000 years ago, although
there may have been prior unsuccessful emigrations. Some of their descendants extended the human range
ever further in each generation, spreading into each habitable land they encountered. One human channel
was along the warm and productive coastal lands of the Persian Gulf and northern Indian Ocean. Eventually,
various bands entered India between 75,000 years ago and 35,000 years ago

The total number of vowels in the given string is 192

The total number of consonents in the given string is 283

The total number of digits in the given string is 20

PROGRAM 14 : STRING OPERATIONS –3

AIM

Write a program to input a sentence. Enter a word separately to find the frequency of the given word in the
sentence. Finally, display the frequency of the given word in the sentence. Finally, display the frequency of
the word.

ALGORITHM

STEP 1 : Start the process


STEP 2 : Accept a string from user and store it in variable mainstr
STEP 3 : Accept the word to be searched from the user and store it in variable s
STEP 4 : Initialize a variable to store the count of occurance of the given word
STEP 5 : Using count method, count and store the frequency of occurance
STEP 6 : Stop the process

FLOWCHART

CODE

mainstr=s=''
mainstr=input(" \n\t Enter a string : ")
s=input(" \n\t Enter a word to be searched : ")

freq=0
freq=mainstr.count(s)

Page 9 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
print( '\n \t The original string is : ', mainstr)

print( '\n \t The frequency of occurance of %s is %s '%(s,freq))

PROGRAM 15 :LIST OPERATIONS - 1

AIM

Write a program to enter a set of numbers in a list. Find and display the maximum and minimum numbers
among them.

ALGORITHM

STEP 1 : Start the process


STEP 2 : Initialize two variables d for values and l for list as null
STEP 3 : Accept integer value from user and store it into d variable . Append it to the
list . Repeat the step until user decides not to store any more values.
STEP 4 : Initialize variable min and max to first element of list.
STEP 5 : Store size=len(l)
STEP 6 : Using FOR loop traverse through each element of the list. And repeat steps 7
and step 8. Goto step 9
STEP 7 : Check if value in ith position of list is lessor than the value in variable min
then, min=l[i]
STEP 8 : Check if value in ith position of list is greater than the value in variable min
then, max=l[i]
STEP 9 : Display the maximum value as max, minimum value as min
STEP 10: Stop the process

CODE

d=0
l=[]
while True:
d=int(input(" \t Enter a value : "))
l.append(d)
ch=input("\t Press y to enter more values in the list otherwise press N : ")
if ch in 'Nn':
break
print(" \t The list of integers is as : \n\t",l)

max=l[0]
min=l[0]
size=len(l)

for i in range(0,size):
if(l[i]>max):
max=l[i]
if (l[i]<min):
min=l[i]

Page 10 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
print("\t The minimum value in the given list is : ", min)
print("\t The maximum value in the given list is : ", max)

OUTPUT

Enter a value : 45
Press y to enter more values in the list otherwise press N : y
Enter a value : 23
Press y to enter more values in the list otherwise press N : y
Enter a value : 56
Press y to enter more values in the list otherwise press N : y
Enter a value : 2
Press y to enter more values in the list otherwise press N : y
Enter a value : 78
Press y to enter more values in the list otherwise press N : y
Enter a value : 33
Press y to enter more values in the list otherwise press N : n
The list of integers is as :
[45, 23, 56, 2, 78, 33]
The minimum value in the given list is : 2
The maximum value in the given list is : 78

PROGRAM 16 : LIST OPERATIONS – 2

Page 11 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS

AIM:

Write a python program to accept a set of names in a list. Enter a name from the user and search for it in the given
list of names. If found then display “Search is successful” otherwise, display “The name is not enlisted ”.

ALGORITHM:

STEP 1 : Start the process


STEP 2 : Initialize three variables : pos as 0 to store length , d for names and l for list as
null
STEP 3 : Accept names from user and store it into d variable . Append it to the
list . Repeat the step until user decides not to store any more values.
STEP 4 : Initialize variable flag =False, size = len(l)
STEP 5 : Accept the name to be searched for from the user and store it in name
STEP 6 : Using FOR loop traverse through each element of the list. And repeat steps 7 Goto step 8
STEP 7 : Check if value in ith position of list is name, then assign flag =True, pos =i
STEP 8 : Check if flag = True, if so, display the position of the name in the list
otherwise, display element not found in the list
STEP 9 : Stop the process

CODE :

pos=0
l=[]
d=''
while True:
d=input(" \t Enter a name : ")
l.append(d)
ch=input("\t Press y to enter more values in the list otherwise press N : ")
if ch in 'Nn':
break
print(" \t The list of names are : \n\t",l)

name=input("\t Enter the name to be searched :")


size=len(l)
flag=False

for i in range(0,size):
if(l[i]==name):
flag=True
pos=i
break

Page 12 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
else:
continue
if flag==True:
print("\t Search is successful")
print( "\t The name %s is found in position %s " %(name,pos+1))
else:
print("\t Search is unsuccessful. No such name exists")

OUTPUT :

Enter a name :ravi


Press y to enter more values in the list otherwise press N : y
Enter a name :sita
Press y to enter more values in the list otherwise press N : y
Enter a name :hari
Press y to enter more values in the list otherwise press N : y
Enter a name :jamuna
Press y to enter more values in the list otherwise press N : n
The list of names are :
['ravi', 'sita', 'hari', 'jamuna']
Enter the name to be searched :hari
Search is successful
The name hari is found in position 3

PROGRAM 17 : LIST OPERATIONS – 3

AIM

Write a python program that allows user to perform any of the list operations given below :
 Create a list with user defined values
 Insert an element at desired position

Page 13 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
 Modify an existing element
 Delete an element using value
 Sort in ascending order
 Sort in descending
 Display the list

ALGORITHM

STEP 1 : Start the process


STEP 2 : Initialize two variables d for values and l for list as null
STEP 3 : Accept integer value from user and store it into d variable . Append it to the
list . Repeat the step until user decides not to store any more values.
STEP 4 : Display the menu as '''\n\t 1. Insert an element at desired position
\n\t 2. Modify an existing element
\n\t 3. Delete an element using value
\n\t 4. Sort in ascending order
\n\t 5. Sort in descending
\n\t 6. Display the list
Choose the option required
STEP 5 : If option =1 , then accept value for a and pos and insert into the list using the insert method. Goto
step 12
STEP 6 : If option =2, then accept the a and pos and change in the location given through pos. Goto step 12
STEP 7 : If option =3, then accept the element to be removed in a and use remove method. Goto step 12
STEP 8 : If option =4, use the sort method to sort the list in ascending order. Goto step 12
STEP 9 : If option =5, use sort method with reverse parameter to sort the list in descending order. Goto step 12
STEP 10 : If option =6, then display the list. Goto step 12
STEP 11 : If option =7, then exit from the iteration. Goto step 13
STEP 12 : If any other option , goto to step 4 otherwise goto step 13
STEP 13 : Stop the process

CODE

list=[]
l=[]
while True:
d=eval(input(" \t Enter a value : "))
l.append(d)
ch=input("\t Press y to enter more values in the list otherwise press N : ")
if ch in 'Nn':
break
print(" \t The list is : \n\t",l)

Page 14 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
ch=0
while ch!=7:
print('''\n\t 1. Insert an element at desired position
\n\t 2. Modify an existing element
\n\t 3. Delete an element using value
\n\t 4. Sort in ascending order
\n\t 5. Sort in descending
\n\t 6. Display the list
\n\t 7. Exit ''')
ch=int(input(" \n\t Enter your choice : "))

if ch==1:
a= eval(input("\t Enter an element :"))
pos = int(input("\t Enter the position at which to be entered :"))
l.insert(pos,a)
elif ch==2:
a= eval(input("\t Enter the new element :"))
pos = int(input("\t Enter the position at which to be changed :"))
l[pos]=a
elif ch==3:
a= eval(input("\t Enter the element to be deleted :"))
l.remove(a)
elif ch==4:
l.sort()
elif ch==5:
l.sort(reverse=True)
elif ch ==6:
print(" \t The list is : \n\t",l)
elif ch==7:
break
else:
print("\n\t Wrong option ! Enter again ..")

OUTPUT

Enter a value : 12
Press y to enter more values in the list otherwise press N : y
Enter a value : 'asd'
Press y to enter more values in the list otherwise press N : y
Enter a value : 56.54
Press y to enter more values in the list otherwise press N : y
Enter a value : 'ter'

Page 15 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
Press y to enter more values in the list otherwise press N : n
The list is :
[12, 'asd', 56.54, 'ter']

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 1


Enter an element :234
Enter the position at which to be entered :2

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 6


The list is :
[12, 'asd', 234, 56.54, 'ter']

1. Insert an element at desired position

2. Modify an existing element

Page 16 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 2


Enter the new element :'lion'
Enter the position at which to be changed :1

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 6


The list is :
[12, 'lion', 234, 56.54, 'ter']

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

Page 17 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
6. Display the list

7. Exit

Enter your choice : 3


Enter the element to be deleted :234

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 6


The list is :
[12, 'lion', 56.54, 'ter']

1. Insert an element at desired position

2. Modify an existing element

3. Delete an element using value

4. Sort in ascending order

5. Sort in descending

6. Display the list

7. Exit

Enter your choice : 7

PROGRAM NO. : 18

Page 18 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
AIM

Write a program to generate random number 1-6, simulating a dice.

ALGORITHM

STEP 1 : Start the process


STEP 2 : import the modules time, random
STEP 3 : initialize variable play as ‘y’
STEP 4 : Generate a random number using randint() between the values 1 and 6 and store
it into the variable n
STEP 5 : Display the value in ‘n’ as random number
STEP 6 : Until user wants to continue the program, go back to step 4, else go to step 7
STEP 7 : Stop the process

CODE

# Program to generate random number between 1 - 6


# To simulate the dice
import random
import time
print("Press CTRL+C to stop the dice ")
play='y'
while play=='y':

n = random.randint(1,6)
print('\n\t\t ',n,' ',end='')
time.sleep(.00001)
print("\n Your Number is :",n)
ans=input("\n Play More? (Y) :")
if ans.lower()!='y':
play='n'
break

OUTPUT

Press CTRL+C to stop the dice


2
Your Number is : 2

Play More? (Y) :Y


1
Your Number is : 1

Page 19 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
Play More? (Y) :N

PROGRAM NO. : 19

AIM

Write a program to generate random number 1-6, simulating a dice.

ALGORITHM

STEP 1 : Start the process


STEP 2 : import the module math
STEP 3 : repeat menu and goto steps 4 to 9 based on user choice, until user selects
choice as exit, then goto step 13
STEP 4 : if choice is 1 then accept value from user , display its squareroot
STEP 5 : if choice is 2 then accept value from user , display its power raised to user given
value
STEP 6 : if choice is 3 then accept value from user , display its log
STEP 7 : if choice is 4 then accept value from user , display its sine value
STEP 8 : if choice is 5 then accept value from user , display its cosine value
STEP 9 : if choice is 6 then accept value from user , display its tan value
STEP 10 : if choice is 7 then accept value from user , display its absolute value
STEP 11 : if choice is 8 then accept value from user , display its ceil value
STEP 12 : if choice is 9 then accept value from user , display its floor value
STEP 13 : Stop the process

CODE

import math
while True :
print("\n\t MENU FOR MATH MODULE FUNCTION ")
print('''\n\t 1.SQRT()
\n\t 2.POW()
\n\t 3.LOG()
\n\t 4.SIN()
\n\t 5.COS()
\n\t 6.TAN()
\n\t 7.FABS()
\n\t 8.CEIL()
\n\t 9.FLOOR()
\n\t 10.EXIT ''')
ch=int(input("\n\t Enter your choice : "))
if ch==1:
S=float(input("\t Enter a value"))

Page 20 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
print("The sqrt of ",S," is ",math.sqrt(S))
elif ch==2:
P=float(input("\t Enter a value"))
q=int(input(" \t Enter the power to which it is to be raised :"))
print("The POW of ",P," is ",math.pow(P,q))
elif ch==3:
S=float(input("\t Enter a value"))
print("The log of ",S," is ",math.log(S))
elif ch==4:
S=float(input("\t Enter a value"))
print("The Sin of ",S," is ",math.sin(S))
elif ch==5:
S=float(input("\t Enter a value"))
print("The Cos of ",S," is ",math.cos(S))
elif ch==6:
S=float(input("\t Enter a value"))
print("The TAN of ",S," is ",math.tan(S))
elif ch==7:
S=float(input("\t Enter a value"))
print("The FABS of ",S," is ",math.fabs(S))
elif ch==8:
S=float(input("\t Enter a value"))
print("The CEIL of ",S," is ",math.ceil(S))
elif ch==9:
S=float(input("\t Enter a value"))
print("The FLOOR of ",S," is ",math.floor(S))
elif ch==10:
break
else:
print(" Entered wrong code")
continue

OUTPUT

MENU FOR MATH MODULE FUNCTION

1.SQRT()
2.POW()
3.LOG()
4.SIN()
5.COS()
6.TAN()
7.FABS()
8.CEIL()

Page 21 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
9.FLOOR()
10.EXIT

Enter your choice : 1


enter a value45
The sqrt of 45 is 6.708203932499369

Enter your choice : 2


Enter a value12
Enter the power to which it is to be raised :3
The POW of 12 is 1728.0

Enter your choice : 3


enter a value10
The log of 10 is 2.302585092994046

Enter your choice : 4


enter a value10
The Sin of 10 is -0.5440211108893698

Enter your choice : 5


enter a value1
The Cos of 1 is 0.5403023058681398

Enter your choice : 6


enter a value45
The TAN of 45 is 1.6197751905438615

Enter your choice : 7


Enter a value-12.2
The FABS of -12.2 is 12.2

Enter your choice : 8


Enter a value56.6
The CEIL of 56.6 is 57

Enter your choice : 9


Enter a value45.6
The FLOOR of 45.6 is 45

Enter your choice : 11

Page 22 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
Entered wrong code

Enter your choice : 10

PROGRAM NO. : 20

AIM

Write a program to calculate the mean, median & mode of a given set of values

ALGORITHM

STEP 1 : Start the process


STEP 2 : import the module statistics
STEP 3 : repeat menu and goto steps 4 to 6 based on user choice, until user selects choice
as exit, then goto step 13
STEP 4 : if choice is 1 then accept list from user and display its mean
STEP 5 : if choice is 2 then accept list from user and display its median
STEP 6 : if choice is 6 then accept list from user and display its mode
STEP 7 : Stop the process

CODE

import statistics
while True :
print("\n\t MENU FOR MATH MODULE FUNCTION ")
print('''\n\t 1.MEAN()
\n\t 2.MEDIAN()
\n\t 3.MODE()
\n\t 4.EXIT ''')
ch=int(input("\n\t Enter your choice : "))
if ch==1:
S=eval(input("\t Enter a list of integer values : "))
print("\t The MEAN of the given list ",S," is ",statistics.mean(S))
elif ch==2:
S=eval(input("\t Enter a list of integer values : "))
print("\t The MEDIAN of the given list ",S," is ",statistics.median(S))
elif ch==3:
S=eval(input("\t Enter a list of integer values : "))
print("\t The MODE of the given list ",S," is ",statistics.mode(S))

elif ch==4:
break
else:

Page 23 of 24
CHENNAI PUBLIC SCHOOL
TH ROAD * SH 50 * THIRUMAZHISAI * CHENNAI – 600 124
RECORD PROGRAMS
print(" \t\t Entered wrong code")
continue

OUTPUT

MENU FOR MATH MODULE FUNCTION

1.MEAN()

2.MEDIAN()

3.MODE()

4.EXIT

Enter your choice : 1


Enter a list of integer values : [12,45,65,12,3,4,89]
The MEAN of the given list [12, 45, 65, 12, 3, 4, 89] is 32.857142857142854

Enter your choice : 2


Enter a list of integer values : [12,45,65,12,3,4,89]
The MEDIAN of the given list [12, 45, 65, 12, 3, 4, 89] is 12

Enter your choice : 3


Enter a list of integer values : [12,45,65,12,3,4,89]
The MODE of the given list [12, 45, 65, 12, 3, 4, 89] is 12

Enter your choice : 6


Entered wrong code

Enter your choice : 4

Page 24 of 24

You might also like