1.
Temperature Conversion (Fahrenheit <-> Celsius)
Algorithm:
1. Start
2. Ask user to choose conversion type
3. If choice is 1, convert Fahrenheit to Celsius
4. If choice is 2, convert Celsius to Fahrenheit
5. Display the result
6. End
Python Program:
print("1: Fahrenheit to Celsius")
print("2: Celsius to Fahrenheit")
choice = int(input("Enter your choice (1 or 2): "))
if choice == 1:
f = float(input("Enter temperature in Fahrenheit: "))
c = (f - 32) * 5/9
print("Temperature in Celsius:", c)
elif choice == 2:
c = float(input("Enter temperature in Celsius: "))
f = (c * 9/5) + 32
print("Temperature in Fahrenheit:", f)
else:
print("Invalid choice")
2. Pattern Printing Using Nested Loop
Algorithm:
1. Start
2. Loop to print increasing stars from 1 to 5
3. Loop to print decreasing stars from 4 to 1
4. Use nested loop to print * based on line number
5. End
Python Program:
# Increasing part
for i in range(1, 6):
for j in range(i):
print("*", end="")
print()
# Decreasing part
for i in range(4, 0, -1):
for j in range(i):
print("*", end="")
print()
3. Grade Calculation Based on Marks
Algorithm:
1. Start
2. Input marks for 5 subjects
3. Calculate total and percentage
4. Check percentage range and assign grade
5. Display total, percentage, and grade
6. End
Python Program:
marks = []
for i in range(5):
m = float(input(f"Enter marks for subject {i+1}: "))
marks.append(m)
total = sum(marks)
percentage = total / 5
if percentage >= 80:
grade = 'A'
elif percentage >= 70:
grade = 'B'
elif percentage >= 60:
grade = 'C'
elif percentage >= 40:
grade = 'D'
else:
grade = 'E'
print("Total Marks:", total)
print("Percentage:", percentage)
print("Grade:", grade)
4. Area Calculation (Rectangle, Square, Circle, Triangle)
Algorithm:
1. Start
2. Ask user to choose shape
3. Based on choice, input required dimensions
4. Apply formula and calculate area
5. Display result
6. End
Python Program:
print("1. Rectangle")
print("2. Square")
print("3. Circle")
print("4. Triangle")
choice = int(input("Enter your choice: "))
if choice == 1:
l = float(input("Enter length: "))
b = float(input("Enter breadth: "))
area = l * b
print("Area of Rectangle:", area)
elif choice == 2:
s = float(input("Enter side: "))
area = s * s
print("Area of Square:", area)
elif choice == 3:
r = float(input("Enter radius: "))
area = 3.14159 * r * r
print("Area of Circle:", area)
elif choice == 4:
b = float(input("Enter base: "))
h = float(input("Enter height: "))
area = 0.5 * b * h
print("Area of Triangle:", area)
else:
print("Invalid choice")