0

time =int(input())

day = time // (24 * 3600)

time = time % (24 * 3600)

hour = time // 3600

time %= 3600

minutes = time // 60

time %= 60

seconds = time

if day > 0:

print((str(int(day))+(" Days"))+(" ")+(str(int(hour))+(" Hours"))+(" ")+(str(int(minutes)) + (" Minutes"))+(" ")+ (str(int(seconds)) + (" Seconds")))

elif hour > 0:

print((str(int(hour)) + " Hours") +(" ") + (str(int(minutes)) + " Minutes") + (" ")+ (str(int(seconds)) + " Seconds"))

elif minutes > 0:

print((str(int(minutes)) + " Minutes") + (" ")+ (str(int(seconds)) + " Seconds"))

else:

print(str(int(seconds)) + " Seconds")
  • 1
    What is wrong with your code? You should add more information. – sagi Feb 01 '22 at 10:37
  • you might want to consider using `datetime.datetime` or `datetime.time` for those types of things. It has very convinient built in methods to handle your problem – RomanHDev Feb 01 '22 at 10:43
  • this might also be helpful https://stackoverflow.com/questions/45140034/python-convert-seconds-to-datetime-date-and-time – RomanHDev Feb 01 '22 at 10:47

2 Answers2

0

you can simple ignore null values by an if condition like:

if (data != np.nan)

or for zero values:

if (data != 0)

or for data greater than and not equal to 0:

if (data != 0) and (data > 0)

and same can be done with elif. you can take "data" variable as any list or value/number.

Sarim Sikander
  • 351
  • 2
  • 15
0

I think you are looking for something like this

from datetime import timedelta, datetime

def timeFormat():
  sec = timedelta(seconds=int(input('Enter seconds')))
  d = datetime(1,1,1) + sec
  # insert some logic here to get rid of values == 0
  print('{} days, {} hours, {} minutes, {} seconds'.format(d.day-1, d.hour, d.minute, d.second))

RomanHDev
  • 104
  • 5