## Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today. # Reverse Numbers game help

I need help with the reverse numbers game. Below is the code I have so far

```import random

secret_num = random.randint(1, 10)
def second_choice():
second_choice = random.randint(1, 10)

def game():
guesses = []
while len(guesses) < 5:
print(secret_num)
guesses.append(secret_num)
guess_again = input("Did I get your number right? Y/n. ")
if guess_again == 'y':
print("You got it")
break
elif guess_again == 'too high':
print('I will choose a higher number')
second_choice()
```

I cannot figure out how to get my computer to guess again and guess a different number and not repeat one he has already guessed. So now I am at a point where I can't get the computer to guess a different number each try. But I am having trouble limiting the computer to 5 tries. Also getting it to guess higher or lower than the previous guess. MOD

I very simple way would be to add an `input` question "do you want to continue" after the `while` loop. If Yes, then simply call `game()` to restart.

This has the minor drawback that this is a recursive call (`game()` calling `game()`) which does have a compiler limit of ~1000 so after 1000 games it might crash with a `RecursionError: maximum recursion depth exceeded`. This is acceptable for this level of coding. ```import random

secret_num = random.randint(1, 10)
def second_choice():
second_choice = random.randint(1, 10)

def game():
guesses = []
while len(guesses) < 5:

print(random.randint(1, 10))

guess_again = input("Did I get your number right? Y/n. ")

if guess_again.lower() == 'y':

print('You got it!')
play_again = input("Do you want to play again? Y/n ")

elif guess_again.lower() == 'n':
game()

game()
``` MOD

It looks like you're not saving the guesses.

• Save `randint` result in variable `guess`
• print `guess`
• adjust the guess by replacing the arguments of the `randint` with `(last_too_low, last_too_high)`
• add code to track `last_too_low` and `last_too_high`