Answer to Question #178732 in Python for surya

Question #178732

For example, if the given seconds are 200. As 200 seconds is equal to 3 minutes and 20 seconds, and days, hours are zero, so ignore the days and hours. So the output should be "3 Minutes 20 Seconds


1
Expert's answer
2021-04-06T16:29:21-0400
""" Program to break down number of seconds into days, hours, minutes, and seconds.
"""

# Get user input
seconds = int(input('Enter seconds: '))

# 1 day = 86400 seconds
days = seconds // 86400

if days > 0:
    print(days, "Days", end=" ")

# 1 hour = 3600 seconds
hours = (seconds - (days * 86400)) // 3600

if hours > 0:
    print(hours, "Hours", end=" ")

# 1 minute = 60 seconds
minutes = (seconds - (days * 86400) - (hours * 3600)) // 60

if minutes > 0:
    print(minutes, "Minutes", end=" ")

remainingSeconds = seconds - (days * 86400) - (hours * 3600) - (minutes * 60)

if remainingSeconds > 0:
    print(remainingSeconds, "Seconds")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS