from itertools import combinations def generate_cage_combinations(total, area, excluded_numbers): # Generate cage combinations for a given total and area, excluding the specified numbers numbers = list(range(1, 10)) cage_combinations = [] # Generate all possible combinations of numbers from 1 to 9 with the given area for combination in combinations(numbers, area): if sum(combination) == total: combination_digits = [int(digit) for number in combination for digit in str(number)] if all(digit not in excluded_numbers for digit in combination_digits): formatted_combination = ' '.join(str(num) for num in combination) cage_combinations.append(formatted_combination) return cage_combinations while True: print('List of Modes') print('For cage overlapping box press A') print('For cage combinations press B') print('For calculator press C') print('To return to the main menu, type zero (0) as your input') opt = input('Mode? ') if 'a' in opt.lower(): print('For cages that overlap more than one box') print("\n") print("____________________ ") print("_________ ____ | ") print("| N ||B || ") print("| || || ") print("| ||___|| ") print("| |_____|____ ") print("| | A |") print("|______________|____|") print(" | ") print("\n") while True: grid_base_number = int(input('Total cage value (N)? ')) if grid_base_number == 0: print("\n") break else: if grid_base_number >= 45: result_a = grid_base_number - 45 result_b = 0 else: result_a = 0 result_b = 45 - grid_base_number print('N = ' + str(grid_base_number)) # Format and count up for result_a a_values = ' '.join('{:>2}'.format(result_a + i) for i in range(19)) print('A = ' + a_values) # Format and count up for result_b b_values = ' '.join('{:>2}'.format(result_b + i) for i in range(19)) print('B = ' + b_values) print("\n") continue elif 'b' in opt.lower(): print('For Cage Combinations') print("\n") print(" ___________________ ") print("| | | |") print("|¦¯¯¯¯¯|¯¯¯¯¯¦| |") print("|¦ N | ¦| |") print("| -----|----- | |") print("| ") print(" (N)sum /range ") print("\n") while True: total = int(input('Cage Total? ')) if total == 0: print("\n") break else: area = int(input('Cage Area? ')) if area == 0: print("\n") break else: excluded_numbers_input = input('Numbers to exclude (leave blank if none): ') excluded_numbers = [int(digit) for digit in excluded_numbers_input if digit.isdigit()] cage_combinations = generate_cage_combinations(total, area, excluded_numbers) print(" " + ' '.join(cage_combinations)) print("\n") further_details = input('Would you like further details? (y/n) ') if further_details.lower() == 'y': n_value = total b_value = int(input('Enter the value for B: ')) a_value = n_value - b_value if (n_value + b_value) <= 45 else 45 - (n_value + b_value) a_values = ' '.join('{:>2}'.format(a_value + i) for i in range(19)) print('A = ' + a_values) print("\n") continue elif 'c' in opt.lower(): print('Calculator') print("\n") while True: expression = input('Enter an expression (+ or -): ') if expression == '0': print('Returning to the main menu...') print("\n") break try: result = eval(expression) print('Result: ' + str(result)) print("\n") except: print('Invalid expression') continue elif opt == '0': print('Returning to the main menu...') print("\n") continue else: print('Invalid mode') continue