You can download this code by clicking the button below.
This code is now available for download.
This function uses the PyInquirer library to randomly select an interactive question, which can be a single choice, input, or confirmation type of question.
Technology Stack : PyInquirer
Code Type : Interactive question selection
Code Difficulty : Intermediate
def select_random_question():
import random
from pyinquirer import prompt, ChoiceQuestion, InputQuestion, ConfirmQuestion
questions = [
ChoiceQuestion('choice_question', 'What is your favorite color? Choose from red, green, blue: ', choices=['red', 'green', 'blue']),
InputQuestion('input_question', 'What is your name? '),
ConfirmQuestion('confirm_question', 'Do you like Python? ')
]
question_type = random.choice(questions).__class__.__name__
question_data = random.choice(questions)
def ask_question():
return prompt(question_data)
return ask_question