A couple of notes for approaching this homework:
- If you are not familiar with the song "The Twelve Days of Christmas", then please let me know so that we can make sure you understand how it works, for the purposes of completing this assignment.
- The logic here is going to be rather complex, involving interacting with a tuple in nested loops.
"""
Write an application that prints the verses
to "The Twelve Days of Christmas". For example, if
the user chooses to print all 12 verses, then the
12th verse will look like this:
On the 12th day of Christmas, my true love sent to me:
Twelve Drummers Drumming
Eleven Pipers Piping
Ten Lords a Leaping
Nine Ladies Dancing
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
"""
import time
lines = ( "Twelve Drummers Drumming",
"Eleven Pipers Piping",
"Ten Lords a Leaping",
"Nine Ladies Dancing",
"Eight Maids a Milking",
"Seven Swans a Swimming",
"Six Geese a Laying",
"Five Golden Rings",
"Four Calling Birds",
"Three French Hens",
"Two Turtle Doves",
"and a Partridge in a Pear Tree" )
days = int(input("How many days should we do? (1 to 12): "))
if not (1 <= days <= 12):
print("Days must be between 1 and 12. Defaulting to 6.")
days = 6
# Loop through the days, from the first
# until the number specified by the user
# NOTE: You may want to process Day 1
# differently than the following days
# YOUR CODE STARTS HERE
# YOUR CODE ENDS HERE
For Day #1, the program will print:
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
For Day #2, it will print:
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
and a Partridge in a Pear Tree
And so forth...
To produce the expected output, you will need to do the following things:
- Print the first line for that day:
On the _____ day of Christmas, my true love gave to me:
Note that, depending on the day, the blank will be filled with "1st", "2nd", "3rd", "4th", etc. You may want to use an if-else statement or a conditional expression for this. (Note that only "1st", "2nd", and "3rd" are irregular. As such, you won't need too many conditions.)
- Like the previous homework assignment, this one will involve nested loops. You have your outer loop that is responsible for the verses -- as well as your inner loop that is responsible for the lines of the current verse.
- Notice that the possible lines are in the tuple in descending order, from 12 through 1. This means that, as the days progress, you can use slices of the tuple to get the lines to print. (HINT: This is a situation where negative tuple indices may come in handy!)
- If you like, you may use the time.delay function to introduce pauses into your program, between verses and lines.
Note that because of user input, the output will look different each time you run the program. To this end, I have provided multiple examples of how the output could look.
Program output examples:
Example 1:
How many days should we do? (1 to 12): 3
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
and a Partridge in a Pear Tree
On the 3rd day of Christmas, my true love gave to me:
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
Example 2:
+ Expand Output
How many days should we do? (1 to 12): 6
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
...
- Collapse Output
How many days should we do? (1 to 12): 6
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
and a Partridge in a Pear Tree
On the 3rd day of Christmas, my true love gave to me:
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 4th day 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 5th day of Christmas, my true love gave to me:
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 6th day of Christmas, my true love gave to me:
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
Example 3:
+ Expand Output
How many days should we do? (1 to 12): 12
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
...
- Collapse Output
How many days should we do? (1 to 12): 12
On the 1st day of Christmas, my true love gave to me:
A Partridge in a Pear Tree
On the 2nd day of Christmas, my true love gave to me:
Two Turtle Doves
and a Partridge in a Pear Tree
On the 3rd day of Christmas, my true love gave to me:
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 4th day 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 5th day of Christmas, my true love gave to me:
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 6th day of Christmas, my true love gave to me:
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 7th day of Christmas, my true love gave to me:
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 8th day of Christmas, my true love gave to me:
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 9th day of Christmas, my true love gave to me:
Nine Ladies Dancing
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 10th day of Christmas, my true love gave to me:
Ten Lords a Leaping
Nine Ladies Dancing
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 11th day of Christmas, my true love gave to me:
Eleven Pipers Piping
Ten Lords a Leaping
Nine Ladies Dancing
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
On the 12th day of Christmas, my true love gave to me:
Twelve Drummers Drumming
Eleven Pipers Piping
Ten Lords a Leaping
Nine Ladies Dancing
Eight Maids a Milking
Seven Swans a Swimming
Six Geese a Laying
Five Golden Rings
Four Calling Birds
Three French Hens
Two Turtle Doves
and a Partridge in a Pear Tree
In at least 150 words, please address the following questions in memo.txt: - How did the process of creating these programs go for you?
- What were your main challenges and how did you overcome them?
- What did you learn that may be of use as you move along in this class?