Support Forums

Full Version: Python help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Ok so for hw I have to calculate # seconds = how much in years, days, hours, minutes, seconds. So if I put in 60 seconds it should come out:
0 years
0 days
0 hours
1 minutes
0 seconds

When I put something it goes to the first thing and then it stops. For example if I put 60 it comes out 0 year and then it stops. How can I make it print through everything?

Code:
seconds_per_year=60*60*24*365
seconds_per_day=60*60*24
seconds_per_hour=60*60
seconds_per_minute=60
seconds_per_second=1
time=input("How Much?")
year=time/seconds_per_year
time=time%seconds_per_year
day=time/seconds_per_day
time=time%seconds_per_day
hour=time/seconds_per_hour
time=time%seconds_per_hour
minute=time/seconds_per_minute
time=time%seconds_per_minute
seconds=time/seconds_per_second
time=time%seconds_per_second

if year>=2:
    print year , "years"
elif day>=2:
    print day , "days"
elif hour>=2:
    print hour , "hours"
elif minute>=2:
    print minute , "minutes"
elif seconds>=2:
    print seconds , "seconds"
elif year<=1:
    print year , "year"
elif day<=1:
    print day , "day"
elif hour<=1:
    print hour , "hour"
elif minute<=1:
    print minute , "minute"
elif second<=1:
    print seconds , "seconds"
Turn the "elif"'s into "if"'s. That should help.
Thanks, that works.