import random


class User:
    def __init__(self, xp_formula, level_formula):
        self.level = 1
        self.xp = 0
        self.xp_to_next_level = xp_formula(
            self.level
        )  # XP needed to reach the next level
        self.xp_formula = xp_formula
        self.level_formula = level_formula

    def earn_xp(self, amount):
        self.xp += amount
        print(f"You earned {amount} XP! Total XP: {self.xp}")

        # Check for level up
        while self.xp >= self.xp_to_next_level:
            self.level_up()

    def level_up(self):
        self.xp -= self.xp_to_next_level
        self.level += 1
        self.xp_to_next_level = self.xp_formula(
            self.level
        )  # Calculate next level requirement
        print(
            f"Congratulations! You've reached Level {self.level}! XP to next level: {self.xp_to_next_level}"
        )


def simulate_xp_gain(user, num_messages, xp_per_message):
    for _ in range(num_messages):
        user.earn_xp(xp_per_message())


def main():
    # Define your formulas here
    def xp_formula(level):
        return int(100 * (1.5 ** (level - 1)))  # Example: 100, 150, 225, 338, ...

    def random_xp_per_message():
        return random.randint(1, 5)  # Random XP between 1 and 10

    user = User(xp_formula, random_xp_per_message)

    while True:
        num_messages = input("Enter the number of messages (or 'quit' to exit): ")

        if num_messages.lower() == "quit":
            break

        if num_messages.isdigit():
            num_messages = int(num_messages)
            simulate_xp_gain(user, num_messages, random_xp_per_message)
        else:
            print("Please enter a valid number.")


if __name__ == "__main__":
    main()
