I have recently started to program in Python. Now im working on a number guessing game. I have a proplem with understanding how does storing a random number works.I have looked around here, found some answer but couldnt make it work. The code works fine, but my answer (random number) is always different, so its imposible to guess it. If anybody could help me or improve my code i would be glad. Here is the part of that code where i have it:
def game(self):
import random
answer = random.randint(0, 1000)
guess = int(input("Your tip is:"))
while True:
if guess < answer:
print ("Your tip is lower, than the answer! Try again.")
self.game()
elif guess > answer:
print ("Your tip is bigger than the answer! Try again.")
self.game()
elif guess == answer:
print ("Good job! You have found the answer!")
self.replay()
Aucun commentaire:
Enregistrer un commentaire