Multiple Calculations - Python Programming Exercise

In this exercise, you will 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. The program will calculate and output the results in a clear and structured format. This task allows you to practice handling basic arithmetic operations and displaying results using the print function in Python. By completing this exercise, you will strengthen your understanding of Python syntax and how to perform various mathematical operations. You will also gain experience in working with user input, creating interactive programs that can process and display multiple results. This is an essential skill for anyone looking to develop practical Python applications while refining their programming skills.

 Category

Your First Steps in Python

 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

 Copy 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

 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.

  •  Times Table

    In this exercise, you will develop a Python program that prompts the user to input two numbers and then displays the results of their addition, subtr...

  •  Calculating the Mean

    In this exercise, you will develop a Python program that calculates and displays the average of four numbers provided by the user. This task allows you ...

  •  Comparative Calculations

    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...

  •  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...