TypeError Too many Arguments

14,369

Solution 1

The issue is that the python input() function was only ready to accept one parameter - the prompt string, but you passed in three. To solve this issue, you just need to combine all three pieces into one.

You can use the % operator to format string:

y = int(input("What power would you like to raise %d to?\n" %x,))

Or use the new way:

y = int(input("What power would you like to raise {0} to?\n".format(x)))

You can find the document here.

Solution 2

Change your y input line to

y = int(input("What power would you like to raise" + str(x) + "to?\n"))

So you will concatenate the three substrings into a single string.

Solution 3

you need to specify x variable :

using format

y = int(input("What power would you like to raise {}to?\n".format(x)))

or

y = int(input("What power would you like to raise %d to?\n"%x)))
Share:
14,369
UrbanConor
Author by

UrbanConor

🦆

Updated on June 26, 2022

Comments

  • UrbanConor
    UrbanConor almost 2 years

    When running this code it appears with an error that there are too many arguments in line 8. I'm unsure on how to fix it.

    #Defining a function to raise the first to the power of the second.
    def power_value(x,y):
        return x**y
    
    ##Testing 'power_value' function
    #Getting the users inputs
    x = int(input("What is the first number?\n"))
    y = int(input("What power would you like to raise",x,"to?\n"))
    
    #Printing the result
    print (x,"to the power of",y,"is:",power_value(x,y))
    

    Resulting in a TypeError...

         Traceback (most recent call last):
      File "C:\[bla location]", line 8, in <module>
        y = int(input("What power would you like to raise",x,"to?\n"))
    TypeError: input expected at most 1 arguments, got 3
    
  • UrbanConor
    UrbanConor over 9 years
    Yes I have used comas to separate them when it should be like that. Thanks :D
  • Matthias
    Matthias over 9 years
    No, it shouldn't be like that. Use format as others suggested.
  • karthikr
    karthikr over 9 years
    Please provide more context to the answer. Moreover, i still see syntax errors in the answer.
  • Cory Kramer
    Cory Kramer over 9 years
    @Matthias "it shouldn't"? Why is that? It works fine.
  • Matthias
    Matthias over 9 years
    It works, but it lacks flexibility. With format you can control the result much better. Additionally: In your example you're missing the blanks around the number. Using a format-string you would see it at once.
  • UrbanConor
    UrbanConor over 9 years
    Thanks, it just I'm not to sure on how the '%' operator works