[Tutor] How to convert seconds to hh:mm:ss format
Dave Angel
d at davea.name
Thu Feb 16 23:21:52 CET 2012
On 02/16/2012 04:46 PM, alain Delon wrote:
> userName = raw_input("Enter your name ")
> print "hi " + userName + ". \n "
> seconds = input("Enter the number of seconds since midnight:")
> hours = seconds/3600
> hoursRemain = hours%60
> minutes = hoursReamain/60
> secondsRemain = minutes%60
> print "hours: " + "minutes: " + "seconds"
>
>
> I'm going to be crazy. Please give me a hand. Thank you very much.
>
Welcome to the list. Are you new to programming, or just to Python, or
just to this list?
Did you copy/paste this from somewhere? Or retype it? Have you tried
running it? What happens?
Is it a learning exercise, or something where you want the results with
the least effort? There are library functions in datetime that'll
practically do it for you, but you don't already know about integer
division and remainders, it's a good exercise to do by hand.
Why do you need help going crazy?
When I try running it, I get indentation errors first, because the code
doesn't line up. next, I get an error because you spelled hoursRemain
two different ways.
Then I get output that doesn't print out any of the results you
calculated. that's because you never print out any of the variables,
only literal strings.
There also, you could use formatting functions, but if you just want to
see the results, print them out with three separate print statements.
Only when you decide they're correct should you worry about making it
pretty, with leading zeroes, colons, and such.
--
DaveA
More information about the Tutor
mailing list