TypeError: Input expected no more than 1 argument, received 3
I am making a little Python game where the computer guesses the number chosen by the player.
# Computer Guessing Game
# The computer tries to guess your number
print("Think of a number, and I will try to guess it. If my guess is right,")
print("say 'yes'.If my guess is too high, say 'lower'. And if my guess is")
print("too low, say 'higher'.\n")
answer = input("Is it 50? ")
guess = 50
while answer != "yes":
hilo = input("Is it higher or lower? ")
if hilo == "lower":
guess %= 50
answer = input("Is it", guess, "?")
if hilo == "higher":
guess %= 150
answer = input("Is it", guess, "?")
print("I win!")
input("Press the enter key to exit.")
However, when running it, lines 15 and 18 of the code
answer = input("Is it", guess, "?")
return "TypeError: Input expected no more than 1 argument, received 3" I don't know how to fix this, so any help would be much appreciated.
+3
source to share
1 answer
input
only takes one argument, you pass it 3. You need to use formatting or string concatenation to make it one argument:
answer = input("Is it {} ?".format(guess))
You confused this with a function print()
that actually takes more than one argument and concatenates the values into one string for you.
+5
source to share