Exercise
Comparative Calculations
Objective
Develop a Python program to prompt the user for three numbers (a, b, c) and display the result of (a + b) * c and the result of a * c + b * c.
Example Python Exercise
Show Python Code
# Prompt the user to enter the first number (a)
a = float(input("Enter the first number (a): "))
# Prompt the user to enter the second number (b)
b = float(input("Enter the second number (b): "))
# Prompt the user to enter the third number (c)
c = float(input("Enter the third number (c): "))
# Calculate and display the result of (a + b) * c
result1 = (a + b) * c
print(f"The result of ({a} + {b}) * {c} is {result1}")
# Calculate and display the result of a * c + b * c
result2 = a * c + b * c
print(f"The result of {a} * {c} + {b} * {c} is {result2}")
Output
Enter the first number (a): 2
Enter the second number (b): 3
Enter the third number (c): 4
The result of (2.0 + 3.0) * 4.0 is 20.0
The result of 2.0 * 4.0 + 3.0 * 4.0 is 20.0
Share this Python Exercise