Python: twelve_days
This commit is contained in:
parent
bbb95d8f0f
commit
7cf9d0f24d
4 changed files with 297 additions and 0 deletions
45
python/twelve-days/twelve_days.py
Normal file
45
python/twelve-days/twelve_days.py
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
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)]
|
||||
Loading…
Add table
Add a link
Reference in a new issue