Help with some python homework...

David bouncingcats at gmail.com
Sat Feb 1 04:17:58 CET 2014


On 1 February 2014 12:34, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Feb 1, 2014 at 12:14 PM, Scott W Dunning <swdunning at cox.net> wrote:
>
>> Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case.  Is that frowned upon?  And should I have come up with a different name instead?
>>
>> SECONDS = 1
>> MINUTES = 60 * SECONDS
>> HOURS = 60 * MINUTES

What is actually being defined here are constants to be used for
scaling or conversion of some quantity (a time) into different units.
So in this situation would I define the conversion constant with an
upper case name like this:

  SECONDS_PER_MINUTE = 60

and I would use it like this

   seconds = minutes * SECONDS_PER_MINUTE

where "seconds" and "minutes" are the names holding the numeric data.

That line has the extra benefit that it is clear to me why the units
are seconds on both sides of the equals sign (because on the right
hand side the minute-units cancel thus: m*s/m=s), whereas this is much
less clear to me in Scott's line.

Scott's message quoted above did not reach me, only Chris's quote of
it, so I say: Scott once you begin a discussion on a mailing list like
this one, please make sure that every reply you make goes to
"python-list at python.org" and not to the individual. That way we can
all participate in the discussion, that is best for everyone
especially you.



More information about the Python-list mailing list