[Tutor] I am puzzled - help needed

Alan Gauld alan.gauld at freenet.co.uk
Thu Mar 31 18:41:23 CEST 2005

> exercise. I need to rewrite the high_low.py program (see below) to
use the
> last two digits of time at that moment to be the "random number".
This is
> using the import time module.
> I just can't work out how to do that, I have been looking at it for
the past
> 2,5 hours but can't break it. Has anyone done it in order for me to
> it.

There are several ways, one is to convert the time number into a
string and
then extract the last two digits and convert back to a number.

n = time.time()
s = str(n)
ran = s[-2:]   # last two characters of the string
ran = int(ran) # convert back to a number

Another option is to divide by 100 and take the remainder...


Alan G.

More information about the Tutor mailing list