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

前端 未结 16 1379
不思量自难忘°
不思量自难忘° 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:06

    #1 min = 60
    #1 hour = 60 * 60 = 3600
    #1 day = 60 * 60 * 24 = 86400
    
        x=input('enter a positive integer: ')
    
        t=int(x)
    
        day= t//86400
        hour= (t-(day*86400))//3600
        minit= (t - ((day*86400) + (hour*3600)))//60
        seconds= t - ((day*86400) + (hour*3600) + (minit*60))
        print( day, 'days' , hour,' hours', minit, 'minutes',seconds,' seconds')
    

提交回复
热议问题