An English Christmas carol.
★★★"The Twelve Days of Christmas" is an English Christmas carol that enumerates in the manner of a cumulative song a series of increasingly numerous gifts given on each of the twelve days of Christmas. - The gift on the first day is a partridge in a pear tree. - The gift on the second day is two turtle doves. - The gift on the third day is three french hens. - The gift on the fourth day is four calling birds. - The gift on the fifth day is five gold rings.
Write a program that outputs the song, “The Twelve Days of Christmas”.
Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.
output_song that:Outputs the song, “The twelve days of Christmas” in the most efficient way.
Hint
Use a list of the days, “first”, “second” etc. Use a list of the gifts. Iterate over both lists.
output_song procedure.On the first of Christmas
My true love gave to me
A partridge in a pear tree.
On the second of Christmas
My true love gave to me
Two turtle doves
And a partridge in a pear tree.
On the third of Christmas
My true love gave to me
Three french hens
Two turtle doves
And a partridge in a pear tree.
On the fourth of Christmas
My true love gave to me
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.
On the fifth of Christmas
My true love gave to me
Five gold rings
Four calling birds
Three french hens
Two turtle doves
And a partridge in a pear tree.
# Twelve days of Christmas program
# -------------------------
# Subprograms
# -------------------------
# Procedure to output the twelve days of Christmas
---
def output_song():
---
day = ["first", "second", "third", "fourth", "fifth"]
item = ["partridge in a pear tree.", "Two turtle doves", "Three french hens", "Four calling birds", "Five gold rings"]
verse = 0
reverse_verse = 0
---
# Output each verse
for verse in range(len(day)):
---
print("On the", day[verse], "day of Christmas")
---
print("My true love gave to me")
---
# All the items from the previous verses are output
for reverse_verse in range(verse, 0, -1):
---
# Output only one partridge!
if reverse_verse > 0:
---
print(item[reverse_verse])
---
# Needs an 'A' or 'And' prefix depending on the verse
if verse == 0:
---
print("A", item[0])
---
else:
---
print("And a", item[0])
---
print()
---
# -------------------------
# Main program
# -------------------------
---
output_song()