1. Write a Python program to find the largest of three numbers.
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
if num1 >= num2 and num1 >= num3:
largest = num1
elif num2 >= num1 and num2 >= num3:
largest = num2
else:
largest = num3
print(f"The largest number is: {largest}")
2. Write a Program to check whether a number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print(f"{num} is even.")
else:
print(f"{num} is odd.")
3. Write a Program to check whether a number is positive, negative, or zero.
num = float(input("Enter a number: "))
if num > 0:
print(f"{num} is positive.")
elif num < 0:
print(f"{num} is negative.")
else:
print("The number is zero.")
4. Write a Python program to check if a character is a vowel or a consonant.
char = input("Enter a single character: ").lower()
if char in ('a', 'e', 'i', 'o', 'u'):
print(f"{char} is a vowel.")
elif char.isalpha():
print(f"{char} is a consonant.")
else:
print("Invalid input! Please enter an alphabetic character.")
5. Write a Python program to calculate the Body Mass Index (BMI) of a The Body Mass
Index (BMI) is a standard measure used to estimate body fat based on an individual’s
height and weight. This metric is applicable to adult men and women. ● Underweight:
BMI less than 18.5 ● Normal weight: BMI between 18.5 and 24.9 ● Overweight: BMI
between 25 and 29.9 ● Obese: BMI of 30 or more
# BMI Calculator
height = float(input("Enter your height in meters: "))
weight = float(input("Enter your weight in kilograms: "))
# Calculate BMI
bmi = weight / (height ** 2)
# Determine BMI category
if bmi < 18.5:
category = "Underweight"
elif 18.5 <= bmi <= 24.9:
category = "Normal weight"
elif 25 <= bmi <= 29.9:
category = "Overweight"
else:
category = "Obese"
# Display result
print(f"Your BMI is: {bmi:.2f}")
print(f"Category: {category}")
6. Write a Python program that determines the type of a triangle based on the lengths of
its sides. (all three sides equal = Equilateral, two sides are equal = Isosceles and all sides
are different = Scalene)
# Triangle Type Checker
side1 = float(input("Enter first side length: "))
side2 = float(input("Enter second side length: "))
side3 = float(input("Enter third side length: "))
if side1 == side2 == side3:
triangle_type = "Equilateral"
elif side1 == side2 or side2 == side3 or side1 == side3:
triangle_type = "Isosceles"
else:
triangle_type = "Scalene"
print(f"The triangle is {triangle_type}.")
7. Write a program to find the factorial of a given number.
num = int(input("Enter a number: "))
factorial = 1
if num < 0:
print("Factorial is not defined for negative numbers.")
elif num == 0 or num == 1:
print(f"The factorial of {num} is 1.")
else:
for i in range(1, num + 1):
factorial *= i
print(f"The factorial of {num} is {factorial}.")
8. Write a program to check whether a number is prime or not.
num = int(input("Enter a number: "))
if num < 2:
print(f"{num} is not a prime number.")
else:
is_prime = True
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
is_prime = False
break
if is_prime:
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")
9. Write a program to generate the Fibonacci series up to n terms
n = int(input("Enter the number of terms: "))
# First two terms
a, b = 0, 1
if n <= 0:
print("Please enter a positive integer.")
elif n == 1:
print(f"Fibonacci series: {a}")
else:
print("Fibonacci series:", a, b, end=" ")
for _ in range(n - 2):
a, b = b, a + b
print(b, end=" ")
10. Write a python program to find the compound intrest and amount .
# Compound Interest Calculator
principal = float(input("Enter the principal amount: "))
rate = float(input("Enter the annual interest rate (in %): "))
time = float(input("Enter the time (in years): "))
n = int(input("Enter the number of times interest is compounded per year: "))
# Calculate compound interest and final amount
amount = principal * (1 + rate / (100 * n)) ** (n * time)
compound_interest = amount - principal
# Display result
print(f"Compound Interest: {compound_interest:.2f}")
print(f"Total Amount after {time} years: {amount:.2f}")
11. Write a python program to convert the temperature from degree Celsius to
fahrenheit
# Take input from the user
celsius = float(input("Enter temperature in Celsius: "))
# Convert Celsius to Fahrenheit
fahrenheit = (celsius * 9/5) + 32
# Display the result
print(f"{celsius}°C is equal to {fahrenheit}°F")