1

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()
McGrady
  • 10,869
  • 13
  • 47
  • 69
Reid
  • 21
  • 1
  • 1
  • 2
  • While `print(thing1, thing2)` prints `thing1` and `thing2` separated by a space, that's a feature of how `print` handles arguments, not a general way to stick multiple things together in any code that produces output. `input` takes at most a single argument to print, which must be a string. – user2357112 Apr 06 '17 at 00:22

4 Answers4

1

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.

Prune
  • 76,765
  • 14
  • 60
  • 81
1

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.

Cory Kramer
  • 114,268
  • 16
  • 167
  • 218
0

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.

mateuszlewko
  • 1,110
  • 8
  • 18
0

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

Felipe Valdes
  • 1,998
  • 15
  • 26