import logging
import random
from .Genericgeneration import Generation

class Classify(Generation):
    """ Classification class for classifying and categorizing number guess.

    Attributes:
		n(integer) - number of attempts
	"""
    def __init__(self, n):
        super().__init__(n)

    def guess_number(self):
        """Function to read in number entered by user in n attempts.
           Compare the user entered number with the number to be guessed.
           If any of guessed numbers entered by the user is greater than,
           lesser than or equal to the number generated by randint function then
           classify accordingly and break from loop using the loop control
           statement(break)

		Args:
			guess(integer): the user entered number

		Returns:
			string: characteristics of guessed number compared to generated
                    number by randint function
		"""
        number = random.randint(1, 20)
        attempts = 0
        while attempts < self.n:
            # Enter a number between 1 to 20
            guess = int(input("Enter numbers between 1 and 20: "))

            if guess == number:
                logging.info('Congratulation YOU WON!!!')
                logging.info('You may start over!!!')
                break
            elif guess > number:
                logging.info(f"Your guess is too high, Guess a number lower than: {guess}")
            else:
                logging.info(f"Your guess is too low, Guess a number higher than: {guess}")

            attempts += 1

        if attempts == self.n:
           logging.info(f"Sorry.. YOU LOSE!!! The number is: {number} ")
           logging.info("You may start over!!!! ")

