Valid month

Valid month

A simple validation routine.

Online forms will check that an input is valid before sending data to a server. For example, when entering an expiry date for a debit card, the month must be between 1 and 12 to be accepted. Doing the basic checks at the client side reduces traffic to and load on the server side.


Write a program that keeps asking the user to enter the month until a valid month has been entered. Valid months are 1-12.

Use this boilerplate code as a starting point:

Success Criteria

Remember to add a comment before a subprogram, selection or iteration statement to explain its purpose.

Complete the subprogram called `validate_month` so that it:

  1. Returns True if the month is greater than or equal to one and less than or equal to twelve.
  2. Returns False in all other cases.

Complete the `main program` so that:

  1. The user can input the month as an integer.
  2. The user is prompted again until they give a valid number within the range one to twelve.
  3. When a valid input is given the program outputs a confirmation message.

Typical inputs and outputs from the program would be:

Enter a month 1-12: 5

Thank you. Input accepted

Enter a month 1-12: -8

Enter a month 1-12: 0

Enter a month 1-12: 13

Enter a month 1-12: 99

Enter a month 1-12: 3

Thank you. Input accepted.

Knowledge Organiser

Use these resources as a reference to help you meet the success criteria.

Programming guide:


Run the unit tests below to check that your program has met the success criteria.

Enter a month 1-12: -3

Enter a month 1-12: 0

Enter a month 1-12: 13

Enter a month 1-12: 22

Enter a month 1-12: 5

Thank you. Input accepted.

Enter a month 1-12: 1

Thank you. Input accepted.

Check that you have:

  • Used comments within the code to describe the purpose of subprograms, conditions and iterations.
  • Used meaningful identifier names. That means the names of subprograms and variables indicate what they are for.
Craig'n'Dave logo

Craig ‘n’ Dave

In partnership with

Mission Encodeable
Bett Awards 2024 Finalist