$ ./guess_the_languageProblem Solving — fix the bug
Problem Solving — fix the bug · medium · #199

Which fix removes the bug?

import math
def area(r):
    return math.pi * r ^ 2
  1. Use ** instead of ^
  2. Import math at the top
  3. Wrap r in float()
  4. Round the result
^ is bitwise XOR in Python, and XOR on a float raises TypeError; exponentiation is **.
Play Problem Solving ▸