[Tutor] I am puzzled - help needed
jfouhy at paradise.net.nz
jfouhy at paradise.net.nz
Thu Mar 31 01:04:35 CEST 2005
Quoting John Carmona <jeannot18 at hotmail.com>:
> Hi John, thanks for the reply.
Hey John,
Please reply to the list, rather than to people directly. Clicking "reply to
all" is probably what you want.
> Ok No. 1, I have read about "ctime" which convert a time expressed in
> seconds since the epoch to a string representing local time
Nah, it's much, much simpler than that.
time.time just returns a floating point number. How do you convert a number
into a string?
> No. 3 why do I need to convert them into an integer, if I manage to get
> the last 2 character this will be a whole number, no?
Programming languages differentiate between numbers and strings. 32 is a
number; you can do computations with it (add, multply, etc). "32" is a string;
this means it is the character "3" followed by the character "2". Python (and
most other programming languages) treats them very differently.
example:
>>> x = 32
>>> x + 1
33
>>> x * 3 / 4
24
>>> s = "32"
>>> s + "1"
'321'
>>> s + "foo"
'32foo'
You have to decide what you need. Your program compars numbers with the answer
(your random number). In order to do this comparison, you need to have your
answer as a number, not as a string.
Hope this helps.
--
John.
More information about the Tutor
mailing list