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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.