PyInquirer-Based Interactive Question Selection

  • Share this:

Code introduction


This function uses the PyInquirer library to create a simple interactive interface where the user can choose an answer from predefined questions.


Technology Stack : PyInquirer

Code Type : Interactive code

Code Difficulty : Intermediate


                
                    
def select_random_question():
    import random
    from pyinquirer import List, Prompt

    questions = [
        "What is your favorite color?",
        "Which programming language do you prefer?",
        "Do you prefer to work with Python or JavaScript?"
    ]

    prompt = Prompt(
        questions=random.choice(questions)
    )

    response = prompt.prompt()

    return response                
              
Tags: