You can download this code by clicking the button below.
This code is now available for download.
This function uses different types of questions from the PyInquirer library, allowing users to choose different interactive ways to answer questions.
Technology Stack : PyInquirer
Code Type : Interactive question selection
Code Difficulty : Intermediate
def select_random_question():
import random
from pyinquirer import prompt, ChoiceQuestion, ListQuestion, ConfirmQuestion, InputQuestion, SecretInputQuestion
questions = [
ChoiceQuestion('choice_question', '请选择一个选项:', choices=['选项1', '选项2', '选项3']),
ListQuestion('list_question', '请选择一个列表项:', choices=['列表项1', '列表项2', '列表项3']),
ConfirmQuestion('confirm_question', '这是一个确认问题,确定吗?'),
InputQuestion('input_question', '请输入一些信息:'),
SecretInputQuestion('secret_input_question', '请输入一些秘密信息:')
]
selected_question = random.choice(questions)
answer = prompt(selected_question)
return answer