Comparative Calculations - Python Programming Exercise

In this exercise, you will develop a Python program to prompt the user for three numbers (a, b, c) and display the result of the expressions (a + b) * c and a * c + b * c. This task teaches you how to handle user input, perform arithmetic calculations, and display results using the print function in Python. It also introduces you to the concept of order of operations in mathematical expressions. By completing this exercise, you will enhance your understanding of Python syntax and become more comfortable with basic mathematical operations. This is an important skill when working with interactive Python programs that require user input and dynamic calculations. Mastering this foundational concept will help you tackle more complex programming tasks and refine your skills in Python.

 Category

Your First Steps in Python

 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

 Copy 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

 More Python Programming Exercises of Your First Steps in Python

Explore our set of Python Programming Exercises! Specifically designed for beginners, these exercises will help you develop a solid understanding of the basics of Python. From variables and data types to control structures and simple functions, each exercise is crafted to challenge you incrementally as you build confidence in coding in Python.

  •  Calculating Years

    In this exercise, you will develop a Python program to prompt the user for their age (e.g., 20) and respond with a message like "You look younger than age...

  •  Data Presentation Styles

    In this exercise, you will develop a Python program to prompt the user for a number and display it four times in a row, separated by spaces, and then four time...

  •  Quadrilateral Dimensions

    In this exercise, you will develop a Python program to prompt the user for a number and then display a rectangle 3 columns wide and 5 rows tall using that d...

  •  Conversion

    In this exercise, you will develop a Python program that asks the user for a temperature in Celsius and converts it to both Kelvin and Fahrenheit...

  •  Initial interaction with Python

    In this exercise, you will develop a Python program to output "Hello" on the screen, followed by your name on a separate line. This exercise is perfect for pra...

  •  Addition of two values

    In this exercise, you will develop a Python program to print the result of adding 12 and 13 on the screen. This exercise is perfect for practicing basic arithm...