16.6k views
3 votes
Here we have a program which is calling the subtract function to calculate the difference between two numbers. The value from the subtract function is being stored in a variable called answer. Then answer is being displayed.

Code is not executing as expected. Instead of seeing the answer, we are seeing the word "None."
Modify the code within the subtract function so the value for solution is returned when the function is called. When you are finished, the output should Desired Output.

# Define the subtraction function
def subtraction(minuend, subtrahend):
solution = minuend-subtrahend
print(minuend,"minus",subtrahend,"equals",solution)

# Call the subtraction function
subtraction(4, 10)

desired output:

10 minus 4 equals 6

User Evan Lenz
by
5.8k points

1 Answer

2 votes

Answer:

See explanation

Step-by-step explanation:

Given

The above program that subtracts two numbers and returns the result

Required

Modify the source code to run perfectly

When the given program is tested, it displays

4 minus 10 equals -6

Which is different from the expected output of

10 minus 4 equals 6

Modify

solution = minuend-subtrahend

to

solution = subtrahend - minuend

And that does it.

User Ydhem
by
4.7k points