import random class game(object): def __init__(self): self.attempts = 0 self.secret = random.randrange(100) def guess(self, number): if self.secret == number: print "You won" self.__init__() else: self.attempts += 1 if self.attempts == 5: print "You lost" self.__init__() else: print "Keep going..."