Interactive Dialogue with PyInquirer

  • Share this:

Code introduction


This function uses the PyInquirer library to create a simple interactive dialogue where the user can input their name, select an option, and confirm if they want to continue.


Technology Stack : PyInquirer

Code Type : Function

Code Difficulty : Intermediate


                
                    
def select_random_option():
    import random
    from pyinquirer import prompt

    questions = [
        {
            "type": "input",
            "name": "name",
            "message": "What is your name?"
        },
        {
            "type": "list",
            "name": "option",
            "message": "Select an option:",
            "choices": ["Option 1", "Option 2", "Option 3"]
        },
        {
            "type": "confirm",
            "name": "confirm",
            "message": "Do you want to continue?"
        }
    ]

    answers = prompt(questions)
    return answers                
              
Tags: