Discussion about this post

User's avatar
Carl Wagner's avatar

For each of the functions in the BasicCalculator class, the print statements should be changed to return statements.

For example:

def subtract(self, a, b):

"""Returns the difference between a and b."""

print(a - b)

should be changed to:

def subtract(self, a, b):

"""Returns the difference between a and b."""

return(a - b)

The "returned" value will then be printed correctly supplied to result and printed when the function is called as below:

result = calculator.subtract(10, 4)

print("Subtraction result:", result)

Expand full comment
Siva's avatar

Using return this the expected output as mentioned by Carl Wagner

Addition result: 8

Subtraction result: 6

Multiplication result: 6

Division result: 4.0

Division result: Error: Division by zero

[Done] exited with code=0 in 0.06 seconds

Expand full comment

No posts