Python function to convert seconds into minutes, hours, and days

前端 未结 16 1389
不思量自难忘°
不思量自难忘° 2020-11-28 07:27

Question: Write a program that asks the user to enter a number of seconds, and works as follows:

  • There are 60 seconds in a minute. If the number of seconds

16条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 08:04

    Do it the other way around subtracting the secs as needed, and don't call it time; there's a package with that name:

    def sec_to_time():
        sec = int( input ('Enter the number of seconds:'.strip()) )
    
        days = sec / 86400
        sec -= 86400*days
    
        hrs = sec / 3600
        sec -= 3600*hrs
    
        mins = sec / 60
        sec -= 60*mins
        print days, ':', hrs, ':', mins, ':', sec
    

提交回复
热议问题