13 Twelve Days of Christmas: Algorithm design

Perhaps one of the worst songs of all time, and the one that is sure to ruin my Christmas spirit, is “The Twelve Days of Christmas.” WILL IT EVER STOP!? AND WHAT IS WITH ALL THE BIRDS?! Still, it’s pretty interesting to write an algorithm to generate the song starting from any given day because you have to count up as you add each verse (day) and then count down inside the verses (recapitulating the previous days’ gifts). You’ll be able to build on what you learned writing the program for “99 Bottles of Beer.”

Our program in this chapter will be called twelve_days.py, and it will generate ...

Get Tiny Python Projects now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.