How to print random strings

Mike Meyer mwm at mired.org
Wed Nov 2 20:00:45 EST 2005


theboringdays at gmail.com writes:

> Im at the end of chapter 3 of "Python Programming For The Absolute
> Beginner, Michael Dawson " and he asks to make a fortune program that
> displays a fortune each time its ran, and to have 5 unique fortunes.
>
> Whats confusing is that, he never discussed how to do this. The only
> thing he talked about was using random.randrange() and I tried that
> with text but it seems like its only for integers as it complains when
> I put text in the argument.
>
> So how would I go about have 5 strings, and running a program that will
> randomly pick one of those to print?
>
> I think he may have forgot to cover something?

Well, randrange can be used to do this, but random.choice is more
pythonic.

        <mike
-- 
Mike Meyer <mwm at mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.



More information about the Python-list mailing list