[Tutor] Help

alan.gauld@bt.com alan.gauld@bt.com
Sun, 7 Apr 2002 23:08:17 +0100


> 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 "?"

Try the first page of the second section of my tutor,
it covers printing things like that using format strings.

You've cracked the hard bit which is the random numbers!

Alternatively you could just string it together in 
a print statement like this:

num1 = ....
num2 = ....
print "What is ", num1, " times ", num2

For more complex things format strings tend to be 
easier IMHO

Alan g.
Author of the 'Learning to Program' web site
http://www.freenetpages.co.uk/hp/alan.gauld