Question 1: Compute the sum, subtraction, multiplication, division, and exponent of two
numbers input by the user.
INPUT
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
print("Sum:", num1 + num2)
print("Subtraction:", num1 - num2)
print("Multiplication:", num1 * num2)
print("Division:", num1 / num2 if num2 != 0 else "Cannot divide by zero!")
print("Exponent:", num1 ** num2)
OUTPUT
Enter first number: 5
Enter second number: 2
Sum: 7.0
Subtraction: 3.0
Multiplication: 10.0
Division: 2.5
Exponent: 25.0
Question 2: Compute the area of a circle, rectangle, triangle, square
INPUT
import math
shape = input("Choose a shape (circle, rectangle, triangle, square): ")
if shape == "circle":
radius = float(input("Enter the radius: "))
area = math.pi * radius ** 2
elif shape == "rectangle":
length = float(input("Enter the length: "))
width = float(input("Enter the width: "))
area = length * width
elif shape == "triangle":
base = float(input("Enter the base: "))
height = float(input("Enter the height: "))
area = 0.5 * base * height
elif shape == "square":
side = float(input("Enter the side length: "))
area = side ** 2
else:
area = "Invalid shape"
print("Area:", area)
OUTPUT
Choose a shape (circle, rectangle, triangle, square): rectangle
Enter the length: 5 ,Enter the width: 3, Area: 15.0
Question 3: Compute the volume of a cube,
INPU
shape = input("Choose a shape (cube, cylinder): ")
if shape == "cube":
side = float(input("Enter the side length: "))
volume = side ** 3
elif shape == "cylinder":
radius = float(input("Enter the radius: "))
height = float(input("Enter the height: "))
volume = math.pi * radius ** 2 * height
else:
volume = "Invalid shape"
print("Volume:", volume)
OUTPUT
Choose a shape (cube, cylinder): cylinder
Enter the radius: 3
Enter the height: 5
Volume: 141.3716694115407
Question 4:Write a program to determine whether a triangle is isosceles or
INPU
a = float(input("Enter side a: "))
b = float(input("Enter side b: "))
c = float(input("Enter side c: "))
if a == b or b == c or a == c:
print("The triangle is isosceles.")
else:
print("The triangle is not isosceles.")
OUTPUT
Enter side a: 5
Enter side b: 5
Enter side c: 3
The triangle is isosceles
Question 5: Print the multiplication table of a number input by the
INPU
num = int(input("Enter a number: "))
for i in range(1, 11):
print(f"{num} x {i} = {num * i}")
OUTPUT
Enter a number: 5
5x1=5
5 x 2 = 10
5 x 3 = 15
5 x 4 = 20
5 x 5 = 25
5 x 6 = 30
5 x 7 = 35
5 x 8 = 40
5 x 9 = 45
5 x 10 = 50
Question 6: Compute the sum of natural numbers from 1 to
INPU
N = int(input("Enter a number N: "))
sum_natural = sum(range(1, N + 1))
print("Sum of natural numbers:", sum_natural)
OUTPUT
Enter a number N: 10
Sum of natural numbers: 55
Question 7: Print the Fibonacci series up to N
INPU
N = int(input("Enter the number of Fibonacci numbers to print: "))
a, b = 0, 1
print("Fibonacci series:")
for _ in range(N):
print(a, end=' ')
a, b = b, a + b
OUTPUT
Enter the number of Fibonacci numbers to print: 5
Fibonacci series:
01123
Question 8: Compute the factorial of a given
INPU
num = int(input("Enter a number: "))
factorial = 1
for i in range(1, num + 1):
factorial *= i
print("Factorial:", factorial)
OUTPUT
Enter a number: 5
Factorial: 120
Question 9: Count the occurrence of the digit 5 in a given integer
INPU
number = input("Enter an integer: ")
count = number.count('5')
print("Occurrences of digit 5:", count)
OUTPUT
Enter an integer: 155555
Occurrences of digit 5: 4
Question 10: Determine prime numbers within a specific range input by the
INPU
start = int(input("Enter start of range: "))
end = int(input("Enter end of range: "))
print("Prime numbers in the range:")
for num in range(start, end + 1):
if num > 1:
for i in range(2, int(num**0.5) + 1):
if num % i == 0:
break
else:
print(num, end=' ')
OUTPUT
Enter start of range: 10
Enter end of range: 20
Prime numbers in the range:
11 13 17 19