# Lesson 16 solution: Mini-Project — The Number-Guessing Game
# This is the completed version of lesson16-practice.py. The secret is
# picked fresh on every run with random.randint(1, 10) — there is no
# fixed secret. On a win it prints "You got it!" plus the tries sentence.
# NOTE: If you run this where no one can type a guess (an automated
# check, for example), it prints a message and stops cleanly instead
# of crashing. Play it in IDLE to play for real.

import random

secret = random.randint(1, 10)
tries = 0

print("I am thinking of a number from 1 to 10.")
print("Can you guess it?")

while True:
    try:
        guess_text = input("Your guess: ")
    except EOFError:
        print("No guess typed, so the game stops here.")
        break
    guess = int(guess_text)
    tries = tries + 1

    if guess == secret:
        print("You got it!")
        print("It took you " + str(tries) + " tries.")
        break
    elif guess < secret:
        print("Too low - try higher.")
    else:
        print("Too high - try lower.")
