Exercise
Multiple Calculations
Objective
Develop a Python program that prompts the user to input two numbers and then displays the results of their addition, subtraction, multiplication, division, and remainder.
It might look like this:
Enter a number: 12
Enter another number: 3
12 + 3 = 15
12 - 3 = 9
12 * 3 = 36
12 / 3 = 4
12 % 3 = 0
Example Python Exercise
Show Python Code
# Prompt the user to enter the first number
num1 = float(input("Enter a number: "))
# Prompt the user to enter the second number
num2 = float(input("Enter another number: "))
# Calculate and display the results of addition, subtraction, multiplication, division, and remainder
print(f"{num1} + {num2} = {num1 + num2}")
print(f"{num1} - {num2} = {num1 - num2}")
print(f"{num1} * {num2} = {num1 * num2}")
print(f"{num1} / {num2} = {num1 / num2}")
print(f"{num1} % {num2} = {num1 % num2}")
Output
Enter a number: 12
Enter another number: 3
12.0 + 3.0 = 15.0
12.0 - 3.0 = 9.0
12.0 * 3.0 = 36.0
12.0 / 3.0 = 4.0
12.0 % 3.0 = 0.0
Share this Python Exercise