You can download this code by clicking the button below.
This code is now available for download.
This function uses the PyInquirer library to create a simple interactive questionnaire where the user can select their favorite color and input their name.
Technology Stack : PyInquirer
Code Type : Function
Code Difficulty : Intermediate
import random
from pyinquirer import prompt, ChoiceQuestion, InputQuestion
def select_random_option(options):
return random.choice(options)
def xxx():
questions = [
ChoiceQuestion('choice', 'What is your favorite color?', ['Red', 'Green', 'Blue']),
InputQuestion('input', 'What is your name?')
]
answers = {}
for question in questions:
answers[question.name] = prompt(question).get('answer')
print(f"Your favorite color is {answers['choice']} and your name is {answers['input']}.")