Random Quote Generator using Questionary Library

  • Share this:

Code introduction


This function uses the Text component from the Questionary library to randomly select a quote from a predefined list of quotes and returns this quote.


Technology Stack : Questionary library, Text component

Code Type : Function

Code Difficulty : Intermediate


                
                    
def generate_random_quote():
    import random
    from questionary import Text

    quotes = [
        "The only way to do great work is to love what you do. - Steve Jobs",
        "The best way to predict the future is to create it. - Peter Drucker",
        "The future belongs to those who believe in the beauty of their dreams. - Eleanor Roosevelt",
        "Success is not final, failure is not fatal: It is the courage to continue that counts. - Winston Churchill"
    ]

    prompt = Text("Choose a random quote for inspiration:", choices=quotes)
    selected_quote = prompt.ask()
    return selected_quote