About the program
This program reads two numbers and passes them to a method.
The method computes the product and the quotient of the two numbers and returns their difference to the main program.
Finally, the main program prints the result.
Python code:
def compute_difference(a, b):
product = a * b
division = a / b if b != 0 else float('inf')
difference = product - division
return difference
# Run the program
num1 = float(input("Enter the first number: "))
num2 = float(input("Enter the second number: "))
result = compute_difference(num1, num2)
print(f"Difference between product and quotient: {result:.2f}")Sample output (input: 6 and 2):
Difference between product and quotient: 9.00How it works:
- Two numbers are read from the user
- Both numbers are passed to a method named compute_difference
- The method computes the product and the quotient
- It then returns the difference of these two values to the main program
- The main program prints the final value