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

29th Jan 2018, 8:20 PM
Abdul Basit
Abdul Basit - avatar
4 ответов
0
@Toni its fine now thanks.
29th Jan 2018, 8:53 PM
Abdul Basit
Abdul Basit - avatar
+ 5
Abdul, mark Toni's answer as the best answer ._. lol
29th Jan 2018, 9:52 PM
Sebastián Zapata
Sebastián Zapata - avatar
+ 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)
29th Jan 2018, 8:48 PM
Toni Isotalo
Toni Isotalo - avatar
+ 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.
30th Jan 2018, 8:49 AM
Abdul Basit
Abdul Basit - avatar