Sunday, September 28, 2025

Python Program Collection 01 - to find sum, product, average and product of two numbers

 


1. Enter any two numbers and display its sum.

first_num = int(input("Enter the first number: "))

second_num = int(input("Enter the second number: "))    

sum = first_num + second_num

print(f"The sum of {first_num} and {second_num} is {sum}")

 

2. Enter any two numbers and display its difference.

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

difference = num1 - num2

print("The difference of two number is:", difference)

 

3. Enter any two numbers and display its product.

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

product = num1 * num2

print(f"The product of {num1} and {num2} is {product}")

 

4. Enter any two numbers and display its average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

average = (num1 + num2) / 2

print("The average of two numbers = ", average)

 

5. Enter any two numbers and display its sum, difference, product and average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

sum_result = num1 + num2

difference = num1 - num2

product = num1 * num2

average = (num1 + num2) / 2

print(f"Sum of two numbers = {sum_result}")

print(f"Difference of two numbers =  {difference}")

print(f"Product of two numbers =  {product}")

print(f"Average of two numbers =  {average}")

 

6. Enter any three numbers and display its sum, product and average.

num1 = float(input("Enter first number: "))

num2 = float(input("Enter second number: "))

num3 = float(input("Enter third number: "))

sum_result = num1 + num2 + num3

product = num1 * num2 * num3

average = (num1 + num2 + num3) / 3

product = num1 * num2 * num3

print(f"Sum of three numbers = {sum_result}")

print(f"Product of three numbers = { product }")

print(f"Average of three numbers = {average}")

 

7. Display square of an input number.

num = float(input("Enter a number: "))

square = num ** 2

print("Square of the number is:", square)

 

8. Display cube of an input number.

num = int(input("Enter a number: "))

square = num ** 3

print("Cube of the number is:", square)

 

9. Display square root of an input number.

num = float(input("Enter a number: "))

sqrt = num ** 0.5   # exponent 0.5 gives square root

print("Square root of", num, "is", sqrt)

 

10. Display cube root of an input number.

num = float(input("Enter a number: "))

cube_root = num ** (1/3)

print(f"Cube root of {num} is {cube_root}")

 

11. Display sum of square of any two input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

sum_of_squares = (a ** 2) + (b ** 2)

print(f"Sum of squares of {a} and {b} is {sum_of_squares}")

12. Display sum of cube of any two input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

sum_of_cubes = (a ** 3) + (b ** 3)

print(f"Sum of cubes of {a} and {b} is {sum_of_cubes}")

 

13. Display sum of square of any three input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third number: "))

sum_of_squares = (a ** 2) + (b ** 2) + (c ** 2)

print(f"Sum of squares of {a}, {b} and {c} is {sum_of_squares}")

 

14. Display sum of cube of any three input numbers.

a = float(input("Enter first number: "))

b = float(input("Enter second number: "))

c = float(input("Enter third number: "))

sum_of_cubes = (a ** 3) + (b ** 3) + (c ** 3)

print(f"Sum of cubes of {a}, {b} and {c} is {sum_of_cubes}")

No comments:

Post a Comment