[Tutor] Help

Kalle Svensson kalle@gnupung.net
Sun, 7 Apr 2002 02:09:19 +0200


[Darren Anthony]
> I want to make python print a sum like:
> What is 7 times 2 ?
> where the two numbers are generated randomly, between 1 and 10.
> 
> So far I have random_between(1,10)
> but how do I include the "What is" and "times" and "?"

Here's one way:

>>> import random
>>> x, y = random.randrange(10), random.randrange(10)
>>> s = "What is %d times %d?" % (x,y)
>>> print s
What is 8 times 5?

Peace,
  Kalle
-- 
Kalle Svensson (kalle@gnupung.net) - Laziness, impatience, hubris: Pick two!
English: http://www.gnupung.net/  Svenska: http://www.lysator.liu.se/~kalle/
Stuff: ["http://www.%s.org/" % x for x in "gnu debian python emacs".split()]