Ask coding questions

← Back to all posts
danielalubezki (1)

def reciprocal(numerator, denominator):

# Returns the reciprocal of a fraction with given numerator and denominator.
rec = numerator/denominator ** -1
return rec

what's wrong with this, why can't I get the reciprocal? Can anyone find the bug?

pyelias (1484)

numerator/denominator ** -1 is equivalent to numerator/(denominator ** -1). You can add parentheses around numerator/denominator to fix this.

danielalubezki (1)

@pyelias It worked! Thank you so much:)