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
totalSeconds = int(input())
secondsPerMinute = 60
secondsPerHour = 60 * secondsPerMinute
secondsPerDay = 24 * secondsPerHour
days = totalSeconds // secondsPerDay
hours = (totalSeconds - days * secondsPerDay) // secondsPerHour
minutes = (totalSeconds - days * secondsPerDay - hours * secondsPerHour) // secondsPerMinute
seconds = totalSeconds - days * secondsPerDay - hours * secondsPerHour - minutes * secondsPerMinute
if days > 0:
print(days, 'Days', end=' ')
if hours > 0:
print(hours, 'Hours', end=' ')
if minutes > 0:
print(minutes, 'Minutes', end=' ')
if seconds > 0:
print(seconds, 'Seconds', end=' ')
print()
Comments
Good python programer
Best python assignemt platform
Leave a comment