[Tutor] Re:Help on Tutor

Lee Harr missive@hotmail.com
Sun Jul 27 10:59:01 2003


>  Your program is exactly what I'm looking for, but could you explain how
>you did that?

>>import time
>>mytime=time.localtime( )
>>number=mytime[4]
>>guess=-1
>>
>>while guess != number:
>>     guess = input("Guess a number: ")
>>
>>     if guess > number :
>>         print "Too high"
>>
>>     elif guess < number :
>>             print "Too low"
>>
>>print "Just right"
>>


One of the great things about python is that if you don't see what is
happening by just reading the code, you can play with the code in the
interactive interpreter:


>>>import time
>>>mytime = time.localtime()
>>>mytime
(2003, 7, 27, 10, 54, 38, 6, 208, 1)
>>>help(time.localtime)
Help on built-in function localtime:

localtime(...)
    localtime([seconds]) -> 
(tm_year,tm_mon,tm_day,tm_hour,tm_min,tm_sec,tm_wday,tm_yday,tm_isdst)

    Convert seconds since the Epoch to a time tuple expressing local time.
    When 'seconds' is not passed in, convert the current time instead.

>>>number = mytime[4]
>>>number
54


Plus, the online documentation is some of the best around:
http://python.org/doc/current/lib/module-time.html

_________________________________________________________________
The new MSN 8: advanced junk mail protection and 2 months FREE* 
http://join.msn.com/?page=features/junkmail