# === TOOLS === def letter_counter(word, letter): """ Count the number of occurrences of a letter in a word or text. Args: word (str): The input text to search through letter (str): The letter to search for Returns: str: A message indicating how many times the letter appears """ word = word.lower() letter = letter.lower() count = word.count(letter) return count def prime_factors(n): """ Compute the prime factorization of a positive integer. Args: n (int): The integer to factorize. Must be greater than 1. Returns: List[int]: A list of prime factors in ascending order. Raises: ValueError: If n is not greater than 1. """ n = int(n) if n <= 1: raise ValueError("Input must be an integer greater than 1.") factors = [] while n % 2 == 0: factors.append(2) n //= 2 divisor = 3 while divisor * divisor <= n: while n % divisor == 0: factors.append(divisor) n //= divisor divisor += 2 if n > 1: factors.append(n) return factors def roll_dice(faces, rolls): """ Simulate rolling dice. Args: faces (int): Number of faces on the die. rolls (int): Number of times to roll the die. Returns: List[int]: A list of results from each roll. """ import random return [random.randint(1, faces) for _ in range(rolls)] def coin_flip(flips): """ Simulate flipping a coin multiple times. Args: flips (int): Number of times to flip the coin. Returns: List[str]: A list of results from each flip ("Heads" or "Tails"). """ import random return ["Heads" if random.randint(0, 1) == 0 else "Tails" for _ in range(flips)]