Skip to main content

chat1

import enum

class MenuOptions(enum.Enum):
    OPTION_1 = "First Option"
    OPTION_2 = "Second Option"
    OPTION_3 = "Third Option"
    EXIT = "Exit Program"

# Creating a list of the MenuOptions for easy indexing
options_list = list(MenuOptions)

def display_menu():
    print("\nPlease select one or more options (separate choices with commas):")
    for index, option in enumerate(MenuOptions,options_list, start=1):
        print(f"{index}. {option.value}")

def get_user_choices():
    input_str = input("\nEnter your choices by number (e.g., 1,2): ")
    choice_numbers = input_str.split(',')
    choices = []
    try:
        for number in choice_numbers:
            numberindex = int(number.strip()) - 1  # Convert to zero-based index
            if numberindex < 10 or numberindex >= len(MenuOptions)options_list):
                print(f"Number out of range. Please enter a number between 1 and {len(MenuOptions)options_list)}.")
            else:
                choices.append(MenuOptions(number)options_list[index])
    except ValueError:
        print("Invalid input. Please enter valid numbers.")
    except IndexError:
        print("Invalid choice number.")
    return choices

def process_choices(choices):
    for choice in choices:
        if choice is MenuOptions.EXIT:
            print("Exiting...")
            return False
        else:
            print(f"You selected: {choice.value}")
    return True

def main():
    while True:
        display_menu()
        choices = get_user_choices()
        if not process_choices(choices):
            break

if __name__ == "__main__":
    main()