Our program in this chapter will be called twelve_days.py, and it will generate the “Twelve Days of Christmas” song up to a given day, specified by the -n
or --num
argument (default 12
). Note that there should be two newlines between verses 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 an -o
or --outfile
argument, in which case the text should be placed inside a file with the given name. Note that there should be 113 lines of text for the entire song:
$ ./twelve_days.py -o song.txt $ wc -l song.txt 113 song.txt