0% found this document useful (0 votes)
2 views20 pages

1-5 Programs - Python

The document outlines five different Python programming exercises, each with a specific aim, algorithm, and program code. The exercises include temperature conversion, student mark list calculation, area of different shapes, Fibonacci series generation, and factorial calculation using recursion. Each program is designed to demonstrate basic programming concepts and has been executed successfully.

Uploaded by

merlinbca
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)
2 views20 pages

1-5 Programs - Python

The document outlines five different Python programming exercises, each with a specific aim, algorithm, and program code. The exercises include temperature conversion, student mark list calculation, area of different shapes, Fibonacci series generation, and factorial calculation using recursion. Each program is designed to demonstrate basic programming concepts and has been executed successfully.

Uploaded by

merlinbca
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

EX.

NO:1
TEMPERATURE CONVERSION
DATE:

AIM:
To write a python program to convert the given temperature from Fahrenheit to Celsius
and vice versa.

ALGORITHM:
Step 1: Start
Step 2: Declare the variable temp and read the input from user
Step 3: if a==’f’
Calculate con_temp=(temp-32) * 5/9
Else:
Calculate con_temp=(9/5*temp) + 32
Step 4: Stop
PROGRAM:
print(“Enter (F) to convert Fahrenheit to Celsius”)
print(“Enter (C) to convert Celsius to Fahrenheit”)
a=input(“Enter your choice:”)
if a==’f’:
temp=int(input(“Enter temperature to convert:”))
con_temp=(temp-32)*5/9
print(temp,’degrees fahrenheit equals’,con_temp,’degree celsius’)
elif a==’c’:
temp=int(input(“Enter temperature to convert:”))
con_temp=(9/5*temp)+32
print(temp,’degrees celsius equals’,con_temp,’degree fahrenheit’)
else:
print(“INVALID CHOICE”)
FLOWCHART
OUTPUT:

Result:
Thus the program has been executed successfully.
[Link]
STUDENT MARK LIST CALCULATION
DATE:

AIM:
To write a python program to calculate total Marks, average and grades of a student.

ALGORITHM:
Step 1: Start
Step 2: Read the input from user (mark1, mark2, mark3, mark4, makr5)
Step 3: Calculate sum and average
Step 4: Display Sum, average and grade
Step 5: Stop
PROGRAM:
mark1=int(input("Enter your English mark:"))
mark2=int(input("Enter your Accounts mark:"))
mark3=int(input("Enter your Business studies mark:"))
mark4=int(input("Enter your Economics mark:"))
mark5=int(input("Enter your Computer science mark:"))
sum=mark1+mark2+mark3+mark4+mark5
print("Total marks=",sum)
avg=sum/5
if (avg>=80):
print("Your grade is A")
elif(avg>=70 and avg<80):
print("Your grade is B")
elif(avg>=60 and avg<70):
print("Your grade is C")
elif(avg>=40 and avg<60):
print("Your grade is D")
elif(avg<40 and avg>=35):
print("Your grade is E")
else:
print("No grade")
FLOWCHART
OUTPUT:

Result:
Thus the program has been executed successfully.
[Link]
AREA OF DIFFERENT SHAPES
DATE:

AIM:
To write a python program to find the area of rectangle, square, circle, triangle.

ALGORITHM:
Step 1: Start
Step 2: Read the input from user for side, length, breadth, radius, height
Step 3: To calculate and display the area of rectangle square, circle and
triangle and call the corresponding function
Step 4: Stop
PROGRAM:
def square(s):
return(s*s)
def rect(l,b):
return(l*b)
def circle(r):
return(3.14*r*r)
def tri(b,h):
return((b*h)/2)
s=int(input(“Enter side:”))
b=int(input(“Enter breadth:”))
l=int(input(“Enter length:”))
r=int(input(“Enter radius:”))
print(“Area of square=”,square(s))
print(“Area of rectangle=”,rect(l,b))
print(“Area of circle=”,circle(r))
print(“Area of triangle=”,tri(b,h))
FLOWCHART
OUTPUT:

Result:
Thus the program has been executed successfully.
[Link]
FIBONACCI SERIES
DATE:

AIM:
To write a python program to display the first n terms of Fibonacci series.

ALGORITHM:
Step 1: Start
Step 2: Declare the variables a, b, c, n, i
Step 3: Initialize variable a=0, b=0, i=0
Step 4: Read the input from the user
Step 5: Repeat until i<n
c=a+b
a=b
b=c
i=i+1
PROGRAM:
def fibonacci(n):
a=0
b=1
i=0
while i<n:
print(a)
c=a+b
a=b
b=c
i=i+1
n=int(input(“Enter the value”))
fib=fibonacci(n)
FLOWCHART
OUTPUT:

Result:
Thus the program has been executed successfully.
[Link]
FACTORIAL USING RECURSION
DATE:

AIM:
To write a python program to find factorial of the give number using
recursive function.

ALGORITHM:
Step 1: Start
Step 2: Read numbers num
Step 3: if num<0 then no value
else call fact(n)
Step 4: Print factorial
Step 5: Stop
PROGRAM:
def fact(n):
if n==1:
return n
else:
return n*fact(n-1)
num=int(input(“Enter a number:”))
if num<0:
print(“NO VALUE”)
elif num==0:
print(“The factorial of 0 is 1”)
else:
print(“The factorial of”, num,” is”, fact(num))
FLOWCHART
OUTPUT:

Result:
Thus the program has been executed successfully.

You might also like