MadLib class question

Hi! I have a habit of overthinking things so if there is a better way to do this please let me know. I’m working on a MadLibs game and I want to give the user the option of choosing from a list of MadLibs. I’m putting each MadLib in a function inside of a class.

I’m still learning all the terminology but would it be possible to take the user’s choice as a variable and then just slot it into the class? Part of the reason I’m posting this is because I don’t know what questions to ask to try and google how to do this? Also I feel like this might be the incorrect way to achieve this.

As an example.

class MadLib:
    def name_of_individual_madlib(self):
        print("blah blah blah")

user_choice = input("Which madlib would you like to do?")
MadLib.user_choice()

I’d include if statements to make sure that user choice matches one of the selections. Thanks for reading and any help or suggestions on how to approach this would be appreciated.

One of the ways this can be done is by storing the functions in a dictionary and retrieve them based on the users input, for instance:

def print_hello(): # Define the function to be retrieved
    print ("hello")

list_of_functions = { 1: print_hello} # Add it to a Dict

def return_input(input): # Function to test the user_input against the Dict
    try:    # Prevent wrong user_input from crashing the program
        return (list_of_functions[input]()) # return the function if the key is present
    except KeyError: # If the key is not present a KeyError will be thrown, catch this!
        print("No such function present") # Provide the user feedback

return_input(1) # Retrieve and call the function, return value will be the return value of the function 

I like the way you are thinking about this! It’s a much more elegant solution then for instance a bunch of if/elif statements