# Arup Guha
# 6/13/2019
# Guessing Game

# This game stops telling you high or low after your first guess that
# is within 5 of the real number. It's a different version and you can
# use different logic to try to reduce the number of guesses.

import random
import math
import time

def main():

    # Generate secret number.
    secret = random.randint(1, 100)

    # Initial values.
    guess = -1
    close = False
    numTurns = 0

    # Start the timer.
    start = time.clock()    
    
    # Play until the user gets it.
    while guess != secret:

        # Get their next guess.
        guess = int(input("What is your guess to the secret number?\n"))
        numTurns += 1
        
        # Get difference
        diff = math.fabs(guess-secret)
        
        # Close!
        if diff <= 5 and diff > 0:
            print("You're really close!!!")
            close = True

        # We only give this feedback if we've never gotten close.
        elif not close and guess > secret:
            print("Your guess is too high. Guess lower.")

        # Same here.
        elif not close and guess < secret:
            print("Your guess is too low. Guess higher.")

    # End the timer.
    end = time.clock()

    print("You got the number in",(end-start),"seconds.")
    
    if numTurns == 1:
        print("You are clairvoyant!!!")
    elif numTurns < 8:
        print("Good job! You got it in",numTurns,"turns.")
    else:
        print("Congrats, you guessed the secret number",secret,"in",numTurns,"turns.")

main()
    
