Twelve Days of Christmas

In this assignment we are going to use the PRIMM approach to help you to develop a new program by modfying an existing one.  PRIMM stands for Predict, Run, Investigate, Model, Make and we looked at the first three stages in the lesson.  If you missed the lesson, then you can watch the recording or look at the questions below in the Predict, Run, Investigate section.

Predict, Run, Investigate

If you attended the lesson then we have already discussed these questions.

Look at the nested loop example in Basthon.  You can copy and paste the code into another IDE such as IDLE.

Before you run the code:

Now investigate the program by asking yourself these questions:

1. Run the program.  How many # symbols are printed altogether?  Could you work out the number instead of counting them?

2. Which variable controls the number of rows?  Which variable controls the number of columns?

3. What would you change if you wanted to print three rows of ten # symbols?

4. What is the purpose of the row variable?  Why is it needed?

5. Could you change the program to print a triangle - i.e. form a triangle number - instead of a rectangle?

6. How would you alter the program to work out the size of a triangle number?

7. What would you do if you wanted the point of the triangle at the bottom, rather than the top?

Modify

Make a copy of the nested loop example in Basthon and make as many of these changes as you are comfortable with.  As you attempt more tasks you will become more confident and will complete more of the steps in future tasks.

  1. Update the program so that it prints the values of x and y rather than printing that number of #s.
  2. Change the inner loop (for x in...) so that it counts down instead of up [hint: you need two three arguments for range()]
  3. Add the following two lines of code at an appropriate point in your program (by copying and pasting):
    ordinal = ("first", "second", "third", "fourth", "fifth", "sixth", "seventh", "eighth", "ninth", "tenth", "eleventh", "twelfth")
    present = ("a partridge in a pear tree", "two turtle doves", "three French hens", "four colly birds", "five gold rings", "six geese a-laying", "seven swans a-swimming", "eight maids a-milking", "nine ladies dancing", "ten lords a-leaping", "eleven pipers piping", "twelve drummers drumming")
    
  4. Extend your program so that it prints the lyrics to the song The Twelve Days of Christmas.
  5. Modify your program so that it counts the total number of presents given over the twelve days of Christmas.