The Twelve Days of Christmas

Christmas“The Twelve Days of Christmas” is an English Christmas carol that enumerates in the manner of a cumulative song a series of increasingly grand gifts given on each of the twelve days of Christmas.

Let’s look at how we could use Python to write the lyrics of a cumulative song.

Learning Objectives


By investigating this program you will understand more how to use lists in Python and how to use loops to iterate through all the values of a list.

Remember, in Python, a list is a collection of values. It uses [square brackets].
For instance:

To find out the number of items in a list we can use the len method.

To iterate through all the items in a list we can use a for loop.

For instance:

We can then use string concatenation techniques to add punctuation:

btnTryCodeOnline

Python Script for The Twelve Days of Christmas:


The code below is used to write the lyrics of this Christmas carol.

Challenge:


Your challenge consists of re-using this script to adapt it to create the lyrics of another cumulative song such as:
Share Button
Posted in Computer Science, Python - Intermediate, Python Challenges

Our Latest Book