Reputation: 19
I'm trying to create a function that will prompt the user to give a radius for each circle that they have designated as having, however, I can't seem to figure out how to display it without running into the TypeError: input expected at most 1 arguments, got 2
def GetRadius():
NUM_CIRCLES = eval(input("Enter the number of circles: "))
for i in range(NUM_CIRCLES):
Radius = eval(input("Enter the radius of circle #", i + 1))
GetRadius()
Upvotes: 0
Views: 19072
Reputation: 2217
In golang
I got the exact same error using database/sql when I tried this code:
err := db.QueryRow("SELECT ... WHERE field=$1 ", field, field2).Scan(&count)
if err != nil {
return false, err
}
it turns out the solution was to do add 1 parameter instead of 2 parameters to the varargs of the function.
so the solution was this:
err := db.QueryRow("SELECT ... WHERE field=$1 ", field).Scan(&count)
// notice field2 is missing here
if err != nil {
return false, err
}
I hope this helps anyone, particularly since this is the first google result when googling this issue.
also guys, always provide context to your errors.
HTH
Upvotes: 0
Reputation: 1129
TypeError: input expected at most 1 arguments, got 2
Thats because you provided two arguments for input function but it expects one argument (yeah I rephrased error message...).
Anyway, use this:
Radius = float(input("Enter the radius of circle #" + str(i + 1)))
Don't use eval
for this. (Other answer explains why)
For future issues, it's worth using help
function from within python interpreter. Try help(input)
in python interpreter.
Upvotes: 0
Reputation: 117856
input
only takes one argument, if you want to create a string with your i
value you can use
Radius = eval(input("Enter the radius of circle #{} ".format(i + 1)))
Also it is very dangerous to use eval
to blindly execute user input.
Upvotes: 1
Reputation: 77827
That's because you gave it a second argument. You can only give it the string you want to see displayed. This isn't a free-form print statement. Try this:
Radius = eval(input("Enter the radius of circle #" + str(i + 1)))
This gives you a single string value to send to input.
Also, be very careful with using eval.
Upvotes: 1