Python 2.7.6 help with modules

Scott W Dunning swdunning at cox.net
Fri Feb 7 23:44:10 EST 2014


I have a question that was a part of my homework and I got it correct but the teacher urged me to do it using the % sign rather than subtracting everything, for some reason I’m having issues getting it to calculate correctly.  I’ll put the question below, and what I originally had and below that what I’ve been working on with the %.   

create a python script for 'Enter the number of Seconds' and get results in weeks, days, hours, minutes and seconds.

This is what I originally submitted for my homework.

seconds = raw_input("Enter the number of seconds:")
seconds = int(seconds)
weeks = seconds / (7*24*60*60)
seconds = seconds - weeks*7*24*60*60
days = seconds / (24*60*60)
seconds = seconds - days*24*60*60
hours = seconds / (60*60)
seconds = seconds - hours*60*60
minutes = seconds / 60
seconds = seconds - minutes *60
print weeks, 'weeks', days, 'days', hours, 'hours', minutes, 'minutes', seconds, 'seconds'

- This is what I’ve been working with.  I get the correct answers for minutes and seconds then it goes to shit after that.  

seconds = raw_input("Enter the number of seconds:")
seconds = int(seconds)
minutes = seconds/60
seconds = seconds % 60
minutes = minutes % 60
hours = seconds/3600
hours = seconds % 3600
days = seconds/86400
days = seconds % 86400
weeks = seconds/604800
weeks = seconds % 604800
print weeks, 'weeks', days, 'days', hours, 'hours', minutes, 'minutes', seconds, 'seconds'

Any help is greatly appreciated!  Thanks again!


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20140207/3b78730a/attachment.html>


More information about the Python-list mailing list