Test Informed Learning with Examples

Logo

Repository with assignments using the Test Informed Learning with Examples (TILE) method to integrate testing into existing programming courses for free.

Menu

Calculating and verifying serial numbers based on dates

Implement a Python program that asks the user for four inputs: a serial number, a day, a month, and a year of production date. First your program has to verify that the given day, month and year correspond to a correct date. If not, your program will notify that on the screen and it will stop. You can finish a program with the instruction exit().

If the date is correct, then you have to check if the serial number corresponds to the production date and print the result on the screen.

The serial number has to be 8 numbers long (remember the use of the len() function), any number with another length is wrong.

Then we should check whether the serial number is correct and inform the user. A serial number is correct when:

  1. The first 4 digits of the number (n1, n2, n3 and n4) meet the following properties:

    1. n1 = (d1 + d2)% 10.

    2. n2 = (m1 + m2)% 10.

    3. n3 = (y1 + y4)% 10.

    4. n4 = (y2 + y3)% 10.

  2. The sum of the last 4 digits of the number (n5, n6, n7 and n8) must be less than 25.

What tests have you run to ensure that your program has the desired behaviour? Note that dates can be incorrect in many ways, make sure your program detects them all and stops when you enter:

Then for correct dates, calculate some serial numbers by hand such that you can test the output of your program.

Insist that the students test their programs by giving them hints on
what to test.