python 2
python 2
INPUT
OUTPUT
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
if shape == "circle":
area = side ** 2
else:
print("Area:", area)
OUTPUT
Choose a shape (circle, rectangle, triangle, square): rectangle
INPU
if shape == "cube":
volume = side ** 3
else:
print("Volume:", volume)
OUTPUT
Volume: 141.3716694115407
Question 4:Write a program to determine whether a triangle is isosceles or
INPU
if a == b or b == c or a == c:
else:
OUTPUT
Enter side a: 5
Enter side b: 5
Enter side c: 3
INPU
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
OUTPUT
Enter a number N: 10
INPU
a, b = 0, 1
print("Fibonacci series:")
for _ in range(N):
a, b = b, a + b
OUTPUT
Fibonacci series:
01123
Question 8: Compute the factorial of a given
INPU
factorial = 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
count = number.count('5')
OUTPUT
Occurrences of digit 5: 4
Question 10: Determine prime numbers within a specific range input by the
INPU
if num > 1:
if num % i == 0:
break
else:
OUTPUT
11 13 17 19