Add number of months to a given month

Challenge Level: Growing experience

Learning outcomes

Students will be able to:

Requirement:

Write a program that asks for a month (as a number between 1 and 12) and the number of months to add to the month as the input and displays the result as the name of a month as the output.

Testing examples:

Your program should display the outputs shown in this table for the given inputs provided;

Input Output
10
4
4 months after October is February.
12
8
8 months after December is August.
1
6
6 months after January is July.
6
6
6 months after June is December.
12
12
12 months after December is December.

Languages

Scratch

What it should look like

Click on the green flag to see the expected output of your program.

Recommended blocks
when green flag clicked
set [new month v] to [0]

set [original month v] to (answer)

set [months to add v] to (answer)

set [new month v] to (((original month) + (months to add)) mod (12))
ask [Type in a number between 1 and 12 for a month of the year:] and wait

ask [Enter the number of months to add to the month:] and wait
say (join (join (months to add) (join [ months after ] (item (original month) of [months v] :: list))) [ is December. ])

say (join (join (join (join (months to add) (join [ months after ] (item (original month) of [months v] :: list))) [ is ]) (item (new month) of [months v] :: list)) [.])
if <(new month) = [0]> then
else
end
Hints
  • Make variables called “original month” and “months to add” and set their values to the inputs entered by the user. Make a variable called “new month” and set its value to the sum of the “original month” and “months to add” modulo 12.
  • Make a list called “months” and add the 12 months; January, February, March, April, May, June, July, August, September, October, November and December to your list (list of length 12).
  • Display the output as December if the value of “new month” is equal to 0 otherwise display the month at the index “new month” as the output.

Show Scratch solution

Python