You can download this code by clicking the button below.
This code is now available for download.
This function uses the Questionary library to generate a series of questions and ask the user randomly, including text input, number input, confirmation, multiple choice, and password input.
Technology Stack : Questionary
Code Type : Function
Code Difficulty : Intermediate
def random_quote():
import random
import questionary as q
questions = [
q.Text("What is your name?", style=q.style.prime),
q.Number("How old are you?", min=0, max=150),
q.Confirm("Do you like Python?", default=True),
q.MultipleChoice(
"What is your favorite programming language?",
choices=["Python", "JavaScript", "Java", "C#"],
style=q.style.prime,
),
q.Password("Enter your password", style=q.style.prime),
]
for question in questions:
print(f"Question: {question}")
print(f"Answer: {question.ask()}")
return questions