PyInquirer Interactive Questionnaire Example

  • Share this:

Code introduction


The function uses the PyInquirer library to create a simple interactive question and answer process, where the user can select an option and enter their name.


Technology Stack : PyInquirer

Code Type : Custom function

Code Difficulty : Intermediate


                
                    
import random
from pyinquirer import prompt, ChoiceQuestion

def custom_pyinquirer_function():
    questions = [
        ChoiceQuestion('Choose an option', ['Option 1', 'Option 2', 'Option 3']),
        InputQuestion('Enter your name', default='John Doe')
    ]
    answers = prompt(questions)
    return answers                
              
Tags: