I'm doing beginner Kata on codewars and I'm confused about the way we used a function.
It has 3 arguments; a, b and margin. Turns out we have to initialise margin to 0 otherwise Python can't find it. But why do we not have to initialise a or b?
The function was close_margin(a, b, margin = 0):
Why not close_margin(a = 0, b = 0, margin = 0):
?
The full code is as follows:
def close_compare(a, b, margin):
if margin == '':
margin = 0
if a < b:
return -1
if a > b:
return 1
difference = a - b
if margin > difference or margin == difference:
return 0
And the resulting error code is:
Traceback (most recent call last):
File "main.py", line 4, in <module>
test.assert_equals(close_compare(4, 5), -1)
TypeError: close_compare() missing 1 required positional argument: 'margin'