exercism-solutions/python/twelve-days/twelve_days.py
2021-06-08 14:34:41 +03:00

45 lines
1.1 KiB
Python

from typing import List
ORDINALS = ['first',
'second',
'third',
'fourth',
'fifth',
'sixth',
'seventh',
'eighth',
'ninth',
'tenth',
'eleventh',
'twelfth']
GIFTS = ['a Partridge in a Pear Tree',
'two Turtle Doves',
'three French Hens',
'four Calling Birds',
'five Gold Rings',
'six Geese-a-Laying',
'seven Swans-a-Swimming',
'eight Maids-a-Milking',
'nine Ladies Dancing',
'ten Lords-a-Leaping',
'eleven Pipers Piping',
'twelve Drummers Drumming']
def _get_gifts_by_day(day: int) -> str:
gift_str = ', '.join(reversed(GIFTS[1:day + 1]))
if gift_str:
gift_str += ', and '
gift_str += GIFTS[0]
return gift_str
def recite(start_verse: int, end_verse: int) -> List[str]:
return [f'On the {ORDINALS[day]} day of Christmas my '
f'true love gave to me: {_get_gifts_by_day(day)}.'
for day in range(start_verse - 1, end_verse)]