Skip to content Skip to sidebar Skip to footer

TypeError Too Many Arguments

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 th

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)))

Solution 4:

input accepts one argument which it prints to the screen. You can read about input() here In your case you are providing 3 arguments to it ->

  1. The String "What power would you like to raise"
  2. The integer x
  3. The String "to?\n"

You can combine these three things together like this and form one argument

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

Post a Comment for "TypeError Too Many Arguments"