Program 1: Calculate Area
This program calculates the area of a rectangle, square, or circle based on user input.
Input:
shape = input("Enter the shape (rectangle/square/circle): ")
if shape == "rectangle":
length = float(input("Enter the length: "))
breadth = float(input("Enter the breadth: "))
area = length * breadth
elif shape == "square":
side = float(input("Enter the side length: "))
area = side ** 2
elif shape == "circle":
radius = float(input("Enter the radius: "))
area = 3.1416 * radius ** 2
else:
area = None
print("Invalid shape.")
if area:
print("Area:", area)
Output:
Enter the shape (rectangle/square/circle): square
Enter the side length: 4
Area: 16.0
Program 2: Pyramid Pattern
This program prints a pyramid pattern using asterisks.
Input:
rows = 3
k = 2 * rows - 2
for i in range(rows):
for j in range(k):
print(" ", end="")
k = k - 1
for j in range(i + 1):
print("* ", end="")
print()
Output:
*
* *
* * *
Program 3: List/Tuple of Subjects
This program creates a list or tuple of subjects and prints them.
Input:
subjects = ["Math", "Physics", "Chemistry", "Biology"]
print("Subjects are:", subjects)
Output:
Subjects are: ['Math', 'Physics', 'Chemistry', 'Biology']
Program 4: Number to String Conversion
This program converts a number to a string and displays the data type before and after conversion.
Input:
num = 123
print("Before conversion:", type(num))
num_str = str(num)
print("After conversion:", type(num_str))
Output:
Before conversion: <class 'int'>
After conversion: <class 'str'>
Program 5: Check Voting Eligibility
This program checks if the user is eligible to vote using an if...else statement.
Input:
age = int(input("Enter your age: "))
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
Output:
Enter your age: 20
You are eligible to vote.