Answer to Question #178448 in Python for CHANDRASENA REDDY CHADA

Question #178448

Date Format - 2

Given seconds as input, write a program to print in D days H hours M minutes S seconds.Input


The input will be a single line containing an integer.Output


The output should be a single line containing the D Days H Hours M Minutes S Seconds format. Print only the non-zero values.Explanation


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"


Sample Input 1

200


Sample Output 1

3 Minutes 20 Seconds


Sample Input 2

86400


Sample Output 2

1 Days




1
Expert's answer
2021-04-05T13:07:46-0400
#Read time
time = int(input(""))
#get days
days = time // (24 * 3600)
time = time % (24 * 3600)
#get hour
hour = time // 3600
time %= 3600
#get minutes
minutes = time // 60
time %= 60
#get seconds
seconds = time

#Print only the non-zero values.
outputTime=""
if days>0:
    outputTime=str(days)+" Days "
if hour>0:
    outputTime+=str(hour)+" Hours "
if minutes>0:
    outputTime+=str(minutes)+" Minutes "
if seconds>0:
    outputTime+=str(seconds)+" Seconds "
#Display time
print(outputTime)

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

Sree
06.10.22, 12:28

Good explanation, thank you...

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS