Readable Duration
Raw seconds are hard to read in an interface, so they are usually converted into years, days, hours, minutes, and seconds. Write format_duration, which takes a non-negative number of seconds and returns a clean English phrase. Use 1 year = 365 days, choose the correct singular or plural forms, separate parts with commas, and place and before the final part. For 0, return now.
Примеры
Ввод
62Вывод
"1 minute and 2 seconds"Ввод
3662Вывод
"1 hour, 1 minute and 2 seconds"Ввод
1Вывод
"1 second"Нужно реализовать
def format_duration(seconds: int) -> str:
Теги
mathstrings
Conectează-te pentru a vedea istoricul soluțiilor trimise
Conectează-teConectează-te pentru a folosi Mentorul AI
Conectează-teVisible tests
1
Input
62Expected
"1 minute and 2 seconds"2
Input
3662Expected
"1 hour, 1 minute and 2 seconds"3
Input
1Expected
"1 second"4
Input
120Expected
"2 minutes"5
Input
0Expected
"now"6
Input
31536000Expected
"1 year"Focus radio
Paused · SomaFM · Fluid