| 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). We’ll be able to build off what you learned writing the "99 Bottles of Beer" song. |
Our program will be called twelve_days.py and will generate the "Twelve Days of Christmas" song up to a given -n or --num argument (default 12). Note that there should be two newlines in between each verse but only one at the end:
$ ./twelve_days.py -n 3 On the first day of Christmas, My true love gave to me, A partridge in a pear tree. On the second day of Christmas, My true love gave to me, Two turtle doves, And a partridge in a pear tree. On the third day of Christmas, My true love gave to me, Three French hens, Two turtle doves, And a partridge in a pear tree.
The text will be printed to STDOUT unless there is a -o or --outfile argument, in which case the text should be placed inside a file by that name. Note there should be 113 lines of text for the entire song:
$ ./twelve_days.py -o song.txt
$ wc -l song.txt
113 song.txt
In this exercise, you will: