Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python help
#1
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"
[Image: 29ol3br.png]
Reply
#2
Turn the "elif"'s into "if"'s. That should help.
[Image: izsyo6.jpg]


Reply
#3
Thanks, that works.
[Image: 29ol3br.png]
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Help Dεlluzion 3 1,749 09-30-2019, 12:59 AM
Last Post: samsmith001
  Simple Python Python Compiler Canoris 21 8,340 06-01-2011, 06:30 PM
Last Post: Filefinder
  Python 2 vs 3? Jake 8 2,218 12-11-2010, 04:13 PM
Last Post: Bursihido
  "==" and "is" in Python Canoris 1 737 02-07-2010, 03:55 PM
Last Post: uber1337
  I Need Help with Python Kharnage 19 3,612 02-06-2010, 08:58 AM
Last Post: Kharnage

Forum Jump:


Users browsing this thread: 1 Guest(s)