Question: Develop a python program to print the lyrics out for all twelve verses, but without defining any lines of lyrics within the program code more

Develop a python program to print the lyrics out for all twelve verses, but without defining any lines of lyrics within the program code more than once. Feel free to substitute your favorite holiday in the lyrics, such as Festivus, New Year, Kwanzaa, Hanukkah, or just a name of a month. In case any of you remember the McKenzie Brothers version of this song, it unfortunately wont work since its too irregular.

Tips: Youll need to use looping, strings, and lists. Try to minimize the number of conditional branches you use (if statements). You should find this list useful for naming the day within each verse:

ordinal_numbers = ['zeroth','first','second','third','fourth','fifth','sixth', 'seventh','eighth','ninth','tenth','eleventh','twelfth']

On the first day of Festivus

my true love gave to me:

a Partridge in a Pear Tree

On the second day of Festivus

my true love gave to me:

2 Turtle Doves

and a Partridge in a Pear Tree

On the third day of Festivus

my true love gave to me:

3 French Hens

2 Turtle Doves

and a Partridge in a Pear Tree

[continuing the pattern until the last verse, which follows:]

On the twelfth day of Festivus

my true love gave to me:

12 Drummers Drumming

11 Pipers Piping

10 Lords a Leaping

9 Ladies Dancing

8 Maids a Milking

7 Swans a Swimming

6 Geese a Laying

5 Golden Rings

4 Calling Birds

3 French Hens

2 Turtle Doves

and a Partridge in a Pear Tree Part 2:

Next, make a second version of your program (either in a second Python file, or as a separate function clearly distinct from the first). Modify it so that as it generates the lyrics, it also calculates the total cumulative number of each gift received, by counting as it runs. You may not hard-code the resulting numbers; the Python program must compute the total numbers.

Instead of printing out the lyrics to the screen as in the first version, this time the output must be sent to two separate text files. One file, called lyrics.txt, should contain just the complete lyrics that result. The second file the program generates should be called gifts.csv. It must be a comma-separated-value file containing a header and two columns gift name and quantity, followed by the 12 lines of data that were computed.

So, for example, the first lines in the gifts.csv output file should be:

gift name, quantity

Partridge in a Pear Tree,12

Turtle Doves,22

Use the accumulator pattern and use an appropriate data type to store the counts of all the gifts within one list structure. Also, you DO NOT need to use the optional CSV module. Like in the Week 5 assignment, we have a very simple structure you can easily output to file with the print() function.

Tip: Note you cant write out results to the gifts.csv file until after the lyrics are done because you need the final counts of each gift.

Finally, if you can see some portion(s) of the two programs that are coded similarly or repetitively, try writing a function (with parameter(s) and return value as appropriate), and use that function in place of the repetitive code. This isnt required to get extra credit, but it will make it better if you do it well. If you try this approach it will be simplest if all your code is in the same python script otherwise, youll have to import the script containing your function definition(s) into the other file before you can call them

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!