[Tutor] Using the TIME module to extract a semi-random number

Katt the_only_katala at verizon.net
Sat Sep 19 06:24:02 CEST 2009


----- Original Message ----- 
> Message: 1
> Date: Wed, 16 Sep 2009 23:19:39 -0400
> From: Kent Johnson <kent37 at tds.net>
> To: Laurii <the_only_katala at verizon.net>
> Cc: tutor at python.org
> Subject: Re: [Tutor] Using the time module to extract a semi-random
> number
> Message-ID:
> <1c2a2c590909162019l364b516cifcd2e0befe2adc87 at mail.gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> On Wed, Sep 16, 2009 at 6:43 PM, Laurii <the_only_katala at verizon.net> 
> wrote:
>
>> The exercise to modify a number guessing program from a fixed number 
>> "number
>> = 78" to using the time module and use the seconds at the time the 
>> program
>> is used to be the number. (i.e. if the clock on your computer says 
>> 7:35:25
>> then it would take the 25 and place it in "number".
>
> time.localtime().tm_sec will give you the number of seconds as an
> integer without any conversions.
>
> Kent
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 17 Sep 2009 10:50:11 +0200
> From: Patrick Sabin <patrick.just4fun at gmail.com>
> To: Tutor at python.org
> Subject: Re: [Tutor] Using the time module to extract a semi-random
> number
> Message-ID: <4AB1F843.1060206 at gmail.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Laurii wrote:
>> Hello all,
>>
>> I am currently reading through the Tutorial for Non-Programers by Josh
>> Cogliati.  I have had great success until now.
>>
>> The exercise to modify a number guessing program from a fixed number
>> "number = 78" to using the time module and use the seconds at the time
>> the program is used to be the number. (i.e. if the clock on your
>> computer says 7:35:25 then it would take the 25 and place it in "number".
>>
>
> You can either use:
>
> import time
> number = int(time.strftime("%S"))
>
> or use real pseudo-random numbers:
>
> import random
> number = random.randint(0,59)
>
> The latter looks clearer to me.

Thank you everyone for your help.  Even just the examples you have posted 
have been easier to understand than the python documentation.

One last question on the TIME module: Is there one version of these examples 
that is not portable to other systems?  I read something about some 
functions not working on other systems and I would like to ensure that the 
programs that I write are completely portable.

Thanks again,

Katt 



More information about the Tutor mailing list