how to ignore zero values

0 votes
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")


input :- 86400 
expected output :- 1 days
output i got :-
1 day 0 hours 0 minutes 0 seconds
Jan 31, 2022 in Python by anonymous

edited Mar 4, 2025 357 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP