+ 3
what is wrong with my code?
Here is the code but i can't figure out what is wrong with in (in python): #!/usr/bin/env python '''guesser game''' import random def main(): randomNumber = random.randint(1,100) found = False while not found: UserGuess = input("Your guess: ") if UserGuess == randomNumber: print("You guessed it!!") found = True elif UserGuess < randomNumber: print("Guess higher!!") else: print("Guess lower!!") if __name__ == "__main__": main()
7 Answers
+ 4
Once the conversion to int change is made, your code works fine for me without any errors on my computer.
If you're running this in the playground, you have to put all of your guesses in at the same time at the prompt. If none of those guesses is correct, then the you'll receive an EOF error because the program is expecting further user input but doesn't receive it. This is just how the code playground handles it and doesn't mean that there is an actual issue with your code. Try making the random number range smaller like 1-10 and then enter all the possible answers. You'll see that the code runs fine without error then.
+ 8
UserGuess is string, a default type returned by input() and you compare it with an integer (a product of randint()
They will never match :)
+ 2
UserGuess = int(input("Your guess: "))
+ 2
Ooooo thx
+ 2
UserGuess = input("Your guess: ")
if UserGuess == randomNumber:
Here you're comparing a str to a number (int)
You need to convert the input (UserGuess) to an int prior to the comparison.
UserGuess = int(input("Your guess: "))
+ 2
What is the error? Where are you trying to run the code?
+ 1
Its an eof error. It has an eof when reading a line