ext_362568 ([identity profile] anyaristow.livejournal.com) wrote in [personal profile] nemorathwald 2009-01-18 08:31 am (UTC)

My first python program :)

def plural( num):
    if num == 1:
        return ""
    else:
        return "s"

totalSeconds = input("How many seconds?")
hours = totalSeconds / 3600
remainingSeconds = totalSeconds % 3600
minutes = remainingSeconds / 60
seconds = remainingSeconds % 60

print str(hours) + " hour" + plural( hours) + ", " + str(minutes) + " minute" + plural( minutes) + ", and " + str(seconds) + " second" + plural( seconds) + "."


Post a comment in response:

This account has disabled anonymous posting.
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting