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
PostgreSQLv16

Le résultat de l'exécution du code s'affichera ici

Visible tests
1
Input
62
Expected"1 minute and 2 seconds"
2
Input
3662
Expected"1 hour, 1 minute and 2 seconds"
3
Input
1
Expected"1 second"
4
Input
120
Expected"2 minutes"
5
Input
0
Expected"now"
6
Input
31536000
Expected"1 year"
Focus radio
Paused · SomaFM · Fluid