0

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
  • 9,744
  • 13
  • 40
  • 63
Reid
  • 11
  • 1
  • 1
  • 1
  • 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

3 Answers3

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
  • 75,308
  • 14
  • 55
  • 76
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
  • 107,498
  • 14
  • 145
  • 201
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,057
  • 8
  • 18