[Tutor] Quote of the Day version 1.0

Christopher King g.nius.ck at gmail.com
Thu Sep 1 21:54:59 CEST 2011


I would use a tuple of dictionaries.
import random

quotes = (
   {'author':"Kahlil Gibran", 'quote':"A candle loses nothing of its light
when
lighting another."), #My favorite
   {'author':"Henrik Ibsen", 'quote':"The strongest man in the world is he
who stands
most alone."})

quote = random.choice(quotes)
print "{quote}\n\tBy {author}".format(**quote)

I use the dictionaries, because your not just storing a list of strings,
your storing two strings of different purposes. I store the dictionaries in
a tuple, because they are all quotes, but they currently never change during
the course of the program. Some quotes have been omitted due to my laziness.
I have not tested or debugged this code(I had to leave you something to do.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20110901/51f61837/attachment.html>


More information about the Tutor mailing list