how do i round off a function.
i have the following code in python
def round(x,n):
return round(x,n)
i get the following error
>>> round(3,98.9898, 2)
Traceback (most recent call last):
File "<pyshell#25>", line 1, in <module>
round(3,98.9898, 2)
TypeError: round() takes exactly 2 arguments (3 given)
i think the comma is creating the problem
any suggestions…. please thanks
i tried this.
def round(x,n):
return round(float(x.replace(",", "")),n)
no luck.
Two issues:
round(3,98.9898, 2)is code that you enter. Omit the comma yourself and your problem goes away. Otherwise give us more info about your problem.def round(x, n): return round(x, n)Even if you fix your function call, you’ll most likely end up with
RuntimeErrordue to maximum recursion. Rename your function to something other thanround.