Home >Backend Development >Python Tutorial >Why Does My Python Guessing Game Throw a 'TypeError: input expected at most 1 arguments, got (more than 1)' Error?
Troubleshooting "TypeError: input expected at most 1 arguments, got (more than 1)
When attempting to create a Python guessing game in which the computer guesses a number chosen by the player, you may encounter the following error:
TypeError: input expected at most 1 arguments, got 3
This error arises from using the input function incorrectly. The input function can only accept a single argument, but you are trying to pass it multiple arguments.
To resolve this issue, you need to use string concatenation or formatting to combine your arguments into a single string that the input function can accept. Here are two ways to do this:
guess = 5 answer = input("Is it " + str(guess) + "?")
guess = 5 answer = input(f"Is it {guess} ?")
In either case, the string concatenation or formatting will create a single string that contains both the text you want to display and the variable guess. The input function can then accept this single string as its argument.
Remember, the print function behaves differently from the input function. print can accept multiple arguments and will automatically concatenate them into a single string. However, input requires only a single argument, which must be a string.
The above is the detailed content of Why Does My Python Guessing Game Throw a 'TypeError: input expected at most 1 arguments, got (more than 1)' Error?. For more information, please follow other related articles on the PHP Chinese website!