You are on page 1of 42

EXP NO:1

DATE :

MATHEMATICAL CALCULATOR
AIM:
To write a python program to design a mathematical
calculator

ALGORITHM:
STEP1: Start
STEP2: Press required number for addition subtraction
multiplication Divison from 1 to n
STEP3: Get two inputs values for calculation
STEP4:If n is equal to 1 then the two values will be
added and the sum values will be printed STEP5:If n is
equal to 2 then the two values will be subtracted and
the difference values will be printed
STEP6:If n is equal to 3 then the two values will be
multiplied and the output will be printed
STEP7: If n is equal to 4 then the two values will be
divided and the output will be printed
STEP8:STOP
CODING:

print("1 for addition , 2 for subraction ,3 for mulitiplication ,4 division ")


n=int(input(" Enter the what arithmetic calculation you need "))
a=int(input())
b=int(input())
if(n==1):
C=a+b
print("Addition of two numbers is ",C)
elif(n==2):
C=a-b
print("Subraction of two numbers is ",C)
elif(n==3):
C=a*b
print("Mulitiplication of the two numbers is ",C)
elif(n==4):
C=a/b
print("Division of two numbers is ",C)
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:2
DATE :

CALCULATE AVERAGE AND GRADE


AIM:
To write a python program to find the average
and grade of the student
ALGORITM:
Step1: Start
Step2: Get 3 inputs of marks
Step3: Calculate the average
Step4: If average is 90 or equal to 100
outstanding.
Step5: If average is 80 excellent.
Step6: If average is above 70 very good. If
average is above 60 good. If average is above
50 poor. If average is less than 50 fail
STEP7:Print grade and average
STEP8:Stop

CODING:
name=str(input("Enter your name "))
dept=str(input("Enter your department"))
reg =int(input("Enter your register number "))
mark1=int(input("Enter your mark1"))
mark2=int(input("Enter your mark2"))
mark3=int(input("Enter your mark3"))
mark4=int(input("Enter your mark4"))
mark5=int(input("Enter your mark 5"))
tot=mark1+mark2+mark3+mark4+mark5
avg=tot/5
if(avg>80 and avg<=100):
print("Passed with distinction")
elif(avg>70 and avg<=80):
print("Passed with A grade")
elif(avg>60 and avg<=70):
print("Passed with B grade ")
elif(avg>50 and avg<=60):
print("Passed with C grade")
else:
print("failed")
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:3
DATE :

SUM OF FIRST N EVEN AND ODD NUMBERS


AIM:
To write a python program for the sum of n even and odd numbers

ALGORITM:
Step1: Start
Step2: Get n values as input for calculation.
Step3: Define sum of even and odd as 0 and define the
starting number as 1

Step4: Use while loop for looping values until condition


is false.

Step5: If num%2 is equal to 0 then add the value of sum


of even numbers with num value.else add the num
value with sum of odd numbers.
Step6: Then permanent the num value the investment
is checked and again it checks with if..else and again
increment value. This increment is looped again and
again untill condition is false.
Step7: Print the sum of even number and odd numbers.
Step8: Stop

CODING:
n=int(input("Enter a number "))
evensum=0
oddsum =0
num=1
while(num<=n):
if(num%2==0):
evensum=evensum+num
else:
oddsum=oddsum+num
num+=1
print("The sum of even numbers is ,",evensum)
print("The sum of odd numbers is ",oddsum)
OUPUT:

RESULT:
Thus the given task is completed
EXP NO:4
DATE :

AREA OF DIFFERENT SHAPES


AIM:
To write a python program for area of different shapes.

ALGORITHM:
Step1: Start
Step2: Press required number for area of required shape
from 1 to 3 Step3: Get required inputs for finding area of
square,rectangle and triangle,circle
Step4: Calculate area of square if 1 is pressed with
formula z=a*a z=a*a.calculate area of rectangle if 2 is
pressed with formula r r=l*b.calculate area of triangle
if 3 is pressed with formula r=l*b.calculate area of
triangle if 3 is pressed with formula r=l*b.calculate
area of triangle if 3 is pressed with formula t=0.5*b*h if
pressed 4 area of circle 3.14*r*r

Step5: Print the area of required shape


Step6: Stop

CODING:
print("press 1 for square ,2 for rectangle,3 for circle,4
for triangle")
n=int(input("Enter the n to find the area"))
if(n==1):
a=int(input("Enter the side of the square"))
area=a*a
print("The area of saquare is ",area )
elif(n==2):
l=int(input("Enter the length"))
b=int(input("Enter the breath"))
area=l*b
print("The area of rectangle is",area)
elif(n==3):
r=int(input("Enter the value of radius"))
area=3.14*r*r
print("The area of circle is",area)
elif(n==4):
h=int(input("Enter the height"))
b=int(input("Enetr the base"))
area=0.5*h*b
print("The area of triangle is",area)

OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:5
DATE :

PRINT THE NUMBERS IN WORDS


AIM:
To write a python program for printing numbers in
words

ALGORITHM:
Step1: Start
Step2: Get a n value
Step3: If n is equal to 1 print one in words
,if n is equal to 2,3,4,5,6,7,8,9 print in
words
Step4: Print the values in words
Step5: Stop.
CODING:
n=int(input("Enter a number "))
if(n==0):
print("0 in words is zero")
elif(n==1):
print("1 in words is one")
elif(n==2):
print("2 in words is two")
elif(n==3):
print("3 in words is three")
elif(n==4):
print("4 in words is four")
elif(n==5):
print("5 in words is five")
elif(n==6):
print("6 in words is six")
elif(n==7):
print("7 in words is seven")
elif(n==8):
print("8 in words is eight")
elif(n==9):
print("9 in words is nine")
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:6
DATE :

A PYTHON PROGRAM FOR CALCULATING


ELAPSED DAYS AND TIME
AIM:
To write a python program for calculating elapsed days
and time

ALGORITHM:
Step 1: Start the program
Step 2: Import date and time
Step 3: Assign the values for A and B
Step 4: Find difference C=A-B
Step 5: Stop the program
CODING:
import datetime
a=datetime.datetime(2017,6,21,18,25,30)
b=datetime.datetime(2017,5,16,8,21,10)
c=a-b
print("difference",c)
minutes=c.total_seconds()/60
print("total difference in minutes ",minutes)
minutes=c.seconds/60
print("difference in minutes ,",minutes)
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:7
DATE :

A PYTHON PROGRAM FOR FINDING FACTORIAL OF A


NUMBER USING RECURSIVE, NON- RECURSIVE
` AND BUILTIN FUNCTIONS.
RECURSIVE:
AIM:
To write a python program for finding factorial of
number using recursive function.

ALGORITHM:
Step1: Start the program:
Step2: Define a function named ’fact’ with argument ‘n’
Step3: Using if..else statement,identify the factorial of a
number using the formula ‘n*fact(n-1)’.
Step4: If the number is not a factorial ,then it returns 1.
Step5: Create a variable named ‘result’ and print the
result.
Step6: Stop the program.
CODING:
def fact(N):
if(N==1):
return 1
else:
return N*fact(N-1)
n=int(input("Enter a number "))
result=fact(n)
print("Factorial of ",n," is",result)
OUTPUT:

RESULT:
Thus the given task is completed
NON RECURSIVE:

AIM:
To write a python program for finding factorial of a
number using non- recursive function

ALGORITHM:
Step1: strat the program.
Step2: Create a variable ‘n’ to get an input from the
user.
Step3: create a variable ‘fact’ with a value 1.
Step4: Use if..else statement to identify whether the
given number is negative since factorial doesn’t exist
for negative numbers.
Step5: If the number is not negative,calculate the and
factorial of the number using ‘fact=fact*i’ in the ‘else’
clause print the result.
Step6: stop the program.
CODING:
n=int(input("Enter a number "))
fact=1
if(n<0):
print("Factorial doesn't exists for neagtive numbers ")
else:
for i in range(1,n+1):
fact=fact*i
print("factorial of n is", fact)
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:8
DATE:

A PYTHON PROGRAM FOR SOLVING TOWERS OF


HANOI
AIM:
To write a python program for solving tower of Hanoi.

ALGORITHM:
Step1: start the program
Step2: Define a function n,source,destination and
auxillary as argument
Step3: Use if statement inside the function
Step4: Call the function
Step5: Stop the program
CODING:
def towers(n,start,destination,auxilary):
if(n==1):
print("move disk 1 from start",start," to destination ",destination)
return
towers(n-1,start,auxilary,destination)
print("move disk ",n,"from start ",start," to destination ",destination)
towers(n-1,auxilary,destination,start)
n=3
towers(n,'A','B','C')
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:9
DATE :

A PYTHON PROGRAM TO CHECK GIVEN


NUMBER/STRING IS PALINDROME
AIM:
To write a python program code for checking the given
number or string is palindrome.

ALGORITHM:
Step1: Start the program
Step2: Define a function with the function name is
palindrome.
Step3: Assign a string.
Step4: Reverse the string to check whether it is a
palindrome.
Step5: Use if-else statement.
Step6: Stop the program.
CODING:
str=input("Enter a string ")
if(str==str[::-1]):
print(str," is a palindrome string")
else:
print(str," is nota palindrome string")
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:10
DATE :

A PYTHON PROGRAM TO COUNT THE NUMBER


OF WORDS,VOWELS IN A PARAGRAPH USING
COMMAND LINE ARGUMENT
AIM:
To write a python program for counting the number of
words,vowels in a paragraph using command line argument.

ALGORITHM:
Step 1: Start the program
Step 2: Initate the variable count at 0
Step 3: Creating the vowels set, Vowels = ( aeiouAEIOU).
Step 4: Transverse the alphabet in the given string.
Step 5: print “ the vowels count “.
Step 6: Stop the program
CODING:
paragraph='python works on different platforms. python has
sytax that allows developers to wwrite program with few
lines than some other programming lanugaes'
def checking(paragraph,vowels):
len(paragraph)
print("no of words in paragraph is ",len(paragraph))
print(paragraph)
res=len(paragraph.split())
print(" the no. of vowels ina paragraph are: "+str(res))
vowels="AaEeIiOoUu"
checking(paragraph,vowels)
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:11
DATE:

A PYTHON PROGRAM TO SORT THE GIVEN


ELEMENTS

AIM:
To write a python program to sort the given elements in
the list

ALGORITHM:
Step1:start
Step2:start a function
Step3: start a for loop range is 5 and declare mid =i
Step4:start a another for loop and declare the range as 6
and if j <mid , mid=j
Step5:swap the contents
Step6:create a list and get input using for loop and
append that with the list and call the function and print
print it after sorting:
Step7: stop
CODING:
def sort(num):
for i in range(5):
mid=i
for j in range(i,5):
if num[j] < num[mid]:
mid=j
temp=num[i]
num[i]=num[mid]
num[mid]=temp
num=[]
for h in range(1,6):
w=int(input("enter the elements in the list"))
num.append(w)
print(" the list before sorting is",num)
sort(num)
print(" the list after sorting is ",num)
OUTPUT:

RESULT:
Thus the given task is completed
EXP NO:12
DATE:

A PYTHON PROGRAM FOR SEARCHING A VALUE IN


BUNCH OF VALUES
AIM:
To write a python program to find a value in bunch of
Values

ALGORITHM:
Step1:start
Step2:position is =-1
Start3:start a function search and now in that declare
L=0 and u=length of the list -1
Start4:now start a while loop and if l<=u declare
mid=l+U//2 and start a if loop and mid value ==n print
that if not change the low value the current mid value
and if not change the high to current mid now create
list and say what element need to be found and call the
function
Step8:stop
CODING:
position=-1
def search(list,n):
l=0
u=len(list)-1
while(l<=u):
mid=(l+u)//2
if(list[mid]==n):
globals()['pos']=mid
return True
else:
if(list[mid]<n):
l=mid
else:
u=mid
list=[10,45,78,52,98,444,63,88]
n=444
if search(list,n):
print("found position is ",pos+1)
else:
print("not found")
OUTPUT:

RESULT:
Thus the given task is completed

You might also like