📖 Beginning Python Programming /
Module: List & Collection

Code Example: Random Quote

📖 Beginning Python Programming / List & Collection / Code Example: Random Quote

Quotes Example v1

from random import randint, choice

quotes = (
    "I want to put a ding in the universe.—Steve Jobs",
    "Life is 10% what happens to you and 90% how you react to it.—Charles R. Swindoll",
    "Family is not an important thing. It's everything.—Michael J. Fox",
    "Nothing is impossible, the word itself says 'I'm possible'!—Audrey Hepburn",
    "There are two ways of spreading light: to be the candle or the mirror that reflects it.—Edith Wharton",
    "Try to be a rainbow in someone's cloud.—Maya Angelou",
    "Be brave enough to live life creatively. The creative place where no one else has ever been.—Alan Alda",
    "The secret of getting ahead is getting started.—Mark Twain",
)


count = len(quotes)
random_index = randint( 0, count-1 )
print( quotes[random_index] )

# or

print( quotes[randint(0,len(quotes)-1)] )

# or

print( choice(quotes) )