I’m learning python with a book that teaches by creating games. I have to write the code so I input a number and the computer makes educated guesses based on higher or lower input. I keep getting an error after inputting my number:
Traceback (most recent call last):
File "C:\Users\Rayvenx\Desktop\My_programs\Number_game_pcguess.py", line 7, in
highlow = raw_input("\nIs it", guess, "?:")
TypeError: [raw_]input expected at most 1 arguments, got 3
Here’s the code:
import random
number = raw_input("\nWhat is your number 1-100? :")
guess = random.randrange(100) + 1
highlow = raw_input("\nIs it", guess, "?:")
while guess != number:
if highlow == "lower":
guess = random.randrange(100) + 1 guess
highlow = raw_input("\nIs it", guess, "?:")
print "\nHaha! I win!"
raw_input("\n\nPress enter to exit game.")
Your problem is that you are giving
raw_inputthree arguments when it expects one 😉But, seriously: your calls which look like
raw_input("is it", guess, "?:")should use Python’s string formatting to format the string being passed toraw_input:raw_input("is it %s?" %(guess, )).