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!
--
https://mail.python.org/mailman/listinfo/python-list