0
Number guessing game in python
I am trying to build a number guessing game in python. I don't know what's wrong with my codes. Can someone spot the mistake? Here are the codes # This is a guess the number game. import random name = input("Hello! Whats you name?\n") print("Well",name, "I am thinking of a number between 1 and 10.\nTake a guess.") my_number = random.randint(1, 10) guess = input("Tr to guess the number: ") while True: if guess > my_number: guess = input("Your guess is too high.Take a guess\n") elif guess < my_number: guess = input("Your guess is too low.Take a guess\n") else: print("You have guessed the number correctly") break
4 Answers
0
@Toni its fine now thanks.
+ 5
Abdul, mark Toni's answer as the best answer ._. lol
+ 1
input() returns a string and you cant use > operator between instances of string and integer.
Parse your guess inputs to integer using int() function.
guess = int(guess)
+ 1
@Sebastian Zapata Mr. Toni has identified the problem and after ammendment in codes its working the way I want it to work. So shouldn't I call it best answer for me? If not this one then what would be the best answer? please elaborate.