# Lesson 16: Mini-Project — The Number-Guessing Game
# WHAT TO DO: This is the full guessing game from the lesson. The
# computer picks a secret number from 1 to 10 with random.randint(),
# the player guesses with input(), and the game counts tries. One line
# is unfinished: in the winning branch, fill in line 35 to report how
# many tries it took, for example:
#     print("It took you " + str(tries) + " tries.")
# HINT: str(tries) turns the tries number into text so it can join the
# message with +. Only change the placeholder line, inside the win branch.
# Run with F5 in IDLE and type guesses when asked. You are done when a
# win prints "You got it!" plus a sentence with your number of tries.
# 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. That is expected — 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("TODO - how many tries did it take?")  # <-- CHANGE THIS LINE
        break
    elif guess < secret:
        print("Too low - try higher.")
    else:
        print("Too high - try lower.")
