This Python program receives two numbers from the user and performs the following arithmetic operations:
- Addition
- Subtraction
- Multiplication
- Division
- Remainder (modulo)
The results are printed clearly for each operation.
# Get two numbers from user
a = float(input("Enter the first number: "))
b = float(input("Enter the second number: "))
# Perform arithmetic operations
sum_result = a + b
sub_result = a - b
mul_result = a * b
div_result = a / b if b != 0 else "Division by zero is not allowed"
mod_result = a % b if b != 0 else "Division by zero is not allowed"
# Display results
print("\n--- Result ---")
print(f"Addition: {sum_result}")
print(f"Subtraction: {sub_result}")
print(f"Multiplication: {mul_result}")
print(f"Division: {div_result}")
print(f"Remainder: {mod_result}")
Enter the first number: 15
Enter the second number: 4
--- Result ---
Addition: 19.0
Subtraction: 11.0
Multiplication: 60.0
Division: 3.75
Remainder: 3.0
- The two numbers are received using input() and converted to float
- Each operation is calculated and stored in a variable
- Division and modulo are protected against division by zero
- Results are printed with clear labels for each operation