Part of the series

Several example codes

~1 min read • Updated Sep 30, 2025

Program Overview

This Python program receives three inputs from the user:
- Two numbers: m and n
- A power value: r
It then calculates and displays the following expressions:
- a = mʳ − nʳ
- b = 2 × m × n
- c = mʳ + nʳ


Python Code:


# Receive inputs from user
m = float(input("Enter value for m: "))
n = float(input("Enter value for n: "))
r = int(input("Enter power r: "))

# Calculate expressions
a = m ** r - n ** r
b = 2 * m * n
c = m ** r + n ** r

# Display results
print("\n--- Result ---")
print(f"a = m^r - n^r = {a}")
print(f"b = 2 * m * n = {b}")
print(f"c = m^r + n^r = {c}")

Sample Output:


Enter value for m: 3  
Enter value for n: 2  
Enter power r: 2  

--- Result ---  
a = m^r - n^r = 5.0  
b = 2 * m * n = 12.0  
c = m^r + n^r = 13.0

Explanation:

- The program receives three inputs: m, n, and r
- Exponentiation is performed using the ** operator
- Each expression is calculated using standard arithmetic and printed with clear labels


Written & researched by Dr. Shahin Siami