chat1
import enum
# Creating a list of the MenuOptions for easy indexing
options_list = list(MenuOptions)
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()