EX NO: 1
TEMPERATURE CONVERSION
DATE:
Aim:
To develop a Python program tha
that converts a given temperature from Fahrenheit to Celsius
or from Celsius to Fahrenheit based on the user's choice.
Algorithm:
Step 1 : Start
Step 2: Get the choice (C / F) and the temperature value from user
Step 3: If choice is F then Calculate F = (C* 9 / 5) + 32
Step 4 : If choice is C then calculate C= (F-
(F 32)*5/9
Step 5 : Print the result F / C
Step 6 : Stop
Flowchart:
Result:
Thus the program has been executed successfully.
EX NO: 2
PATTERN USING NESTED LOOP
DATE:
Aim :
To write a python program to print a pattern with the given character.
Algorithm :
Step 1 : Start
Step 2: Get the no. of rows ‘n’ from user
Step 3: Print the character * to get the desired pattern starting from 1 up to ‘n’ times
in each line
Step 4 : Now Print the character * to starting from ‘n-1’
‘n 1’ and up to 1 time
in each line
Step 5 : Stop
Flowchart:
Result :
The given program has been executed successfully.
EX NO: 3
STUDENT GRADE CALCULATION
DATE:
Aim :
To write a python program to calculate total marks, percentage and grade
of student.
Algorithm :
Step 1 : Start
Step 2: Get the marks obtained in 5 different subjects from the user
Step 3: Calculate total = m1 + m2+m3+m4+m5
Step 4 : Calculate avg = total / 5.
Step 5 : Check if all marks are greater than 30:
If any mark is less than or equal to 30, set grade = "Fail" and stop
further calculations.
Step 6 : Determine the grade based on the average:
If avg >= 80 then grade = 'A'
Else if avg >= 70 and avg < 80 then grade = 'B'
Else if avg >= 60 and avg < 70 then grade = 'C'
Else if avg >= 40 and avg < 60 then grade = 'D'
Else if avg < 40 then grade = 'E'
Step 7: Stop
Department of Computer Science with Artificial Intelligence
Flowchart:
Program:
sub1 = float(input("Enter marks of the first subject: "))
sub2 = float(input("Enter marks of the second subject: "))
sub3 = float(input("Enter marks of the third subject: "))
sub4 = float(input("Enter marks of the fourth subject: "))
sub5 = float(input("Enter marks of the fifth subject: "))
tot = sub1 + sub2 + sub3 + sub4 + sub5
avg = tot / 5
print("Total Marks =", tot)
print("Marks Percentage =", avg)
if avg >= 80:
print("Grade: A")
elif avg >= 70:
print("Grade: B")
elif avg >= 60:
print("Grade: C")
elif avg >= 40:
print("Grade: D")
else:
print("Grade: E")
Result :
The given program has been executed successfully.
EX NO: 4
AREA OF A SHAPE
DATE:
Aim:
To write a python program To Find The Area Of Rectangle, Square, Circle And triangle by
accepting suitable input parameters from user
Algorithm :
Step 1 : Start
Step 2: Get the choice(1 – square 2-rectangle 3-triangle 4-circle) from the user
Step 3 : Determine the area of shape based on user choice:
If choice = 1 then get the square side value
Calculate area = side * side
If choice = 2 then get the length l and breadth b value of rectangle
Calculate area of = l * b
If choice = 3 then get the base b and height h value of triangle
Calculate area = 1/2 * b * h
If choice = 4 then get the radius r value of circle
Calculate area = 3.14 * r * r
Else print invalid choice
Step 4: Print area
Step 5: Stop
Department of Computer Science with Artificial Intelligence
Flowchart:
Program
i="Find area\nchoose your ptions\n1.square\n2.rectangle\n3.triangle\n4.circle"
print(i)
choice=int(input("Enter your option:"))
if choice==1:
z=int(input("Enter your value:"))
print("Square area is :",z**2)
elif choice==2:
a=int(input("Enter your Width value "))
b=int(input("Enter your length value :"))
print("Rectangle area is :",a*b)
elif choice==3:
c=int(input("Enter your base height value:"))
d=int(input("Enter your base value :"))
print("Triangle area is :",c*d/2)
elif choice==4:
e=int(input("Enter your radius value:"))
print("Circle area is:",int((e*e)*22/7))
else:
print("Your number is wrong")
Department of Computer Science with Artificial Intelligence
Result :
The given program has been executed successfully.
EX NO: 5
PRIME NUMBERS
DATE:
Aim:
To write a python program to print prime numbers less than 20.
Flowchart:
Program
starting_value = 1
n = int(input("Enter your number: "))
print("Prime numbers between", starting_value, "and", n, "are:")
for num in range(starting_value, n + 1):
if num > 1:
for i in range(2, num):
if (num % i) == 0:
break
else:
print(num)
Result
Thus the program has been executed successfully .