## Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

### Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

import random

# create game function

def game(): #create random integer secret_num = random.randint(1, 10) #empty array to store guesses guesses = [] #print secret number for cheating print (secret_num)

```#run the loop while there are still less than 5 guesses
while len(guesses) < 5:
#safely get an integer as input
try:
guess = int(input("Guess a number between 1 and 10.: "))
except ValueError:
print("{} enter a number.".format(guess))
#continue of there's no error
else:
#if the guess is correct print success message and end
if guess == secret_num:
print("You got it! It was {}".format(secret_num))
break
#if the guess is too high, say so
elif guess > secret_num:
print("Too high")
continue
#if it's too low, say so
elif guess < secret_num:
print("Too low")
continue
#after each run through of the loop add the guess to the array of guesses
guesses.append(guess)
play_again = input("Wanna play again? (Y/N)")
if play_again.lower() != "n":
game()
else:
print("Bye!")
```

game()