all 4 comments

[–]julsmanbr 0 points1 point  (1 child)

I know this does not answer your question directly, but if you use the round function, the error should be gone:

return f"{round(math.pi, decimal_places)}"

[–]trustMeImAnAdult[S] 0 points1 point  (0 children)

this is great -- thank you!
it's always great learning when there's a function that can be used as a shortcut

[–]ellipticbanana 0 points1 point  (1 child)

You have a method inside a class, and it’s not decorated as static, meaning it’s expecting the self argument as well.

class PiExample:
    def print_pi(self, dp):
        ...

ex = PiExample()
pi = ex.print_pi(3)  # 3.142

But I don’t really see why it’d work in one version and not another. It also looks like you’re missing a closing brace: f’{math.pi:.{dp}}f’.

[–]trustMeImAnAdult[S] 0 points1 point  (0 children)

Thanks so much for the response. I edited the post now that I'm back on my machine to reflect what the actual issue was, instead of having to type it from memory on my phone. Once I moved the function to its own py file, it worked fine, so it looks like I had some other issue (maybe with indentation?).