Description
Department of Computer Engineering
Take Home Exam 2
REGULATIONS
Submission: Electronically. You should save your program source code as a text file named the2.py and submit it to us via the course’s COW page.
Team: There is no teaming up. This is an EXAM.
Cheating: Source(s) and Receiver(s) will receive zero and be subject to disciplinary action.
INTRODUCTION
A check digit is a form of redundancy check used for error detection on identification numbers, such as bank account numbers, which are used in an application where they will at least sometimes be input manually. It consists of one or more digits computed by an algorithm from the other digits (or letters) in the sequence input.
With a check digit, one can detect simple errors in the input of a series of characters (usually digits) such as a single mistyped digit or some permutations of two successive digits.
• sum← 0
• For each digit in the student number that has an odd position (first, third, fifth) take the digit and add it to the sum.
• For each digit in the student number that has an even position (second, forth, sixth) take twice the digit. If this result of doubling is a two digit number then add each of these digits to the sum, otherwise add the result of the doubling (which is a single digit number itself) to the sum.
• The one digit number, which when added to the sum results in a multiple of 10, is the check digit
Take as example the student number of 167912
1 6 791 2
2✕6 2✕9 2✕2
=12 =18 =4
1+ + + + + + +1 2 7 1 8 1 4 =25
25+5=30 ([Closest multiple of ten]≥25) This becomes the check digit
The check digit of the student number 167912 is found to be 5. As you all well know, this is written as 167912-5. That is called the student-id.
PROBLEM & SPECIFICATIONS
Your mission, should you choose to accept it, is to determine the digit that is missing from a METU student-id or if no digit is missing to determine whether it is valid or not. A student-id will be read from the standard input as
######-#
where each # is a decimal digit or a ‘?’ (question mark). There will be at most one question mark. It is also possible that no question mark appears in the input. You will be printing a single line of output which strictly follows the below given specification:
• There is no question mark: Print VALID if the check digit is correct. Otherwise print INVALID.
• Check digit position is question marked: Compute the check digit and print the whole student-id (with the correct check digit present).
• One of the first six digit position is question marked: Compute the digit position that is question marked and print the whole student-id (with the correct digit present).
FIVE EXAMPLE RUNS
>>> 167912-5
VALID
>>> 167912-?
167912-5
>>> 1679?2-5
167912-5
>>> 1679?2-5
167912-5
>>> 13?503-7
139503-7
GRADING
Comply with the specifications. Do not try to beautify neither the input nor the output. Your program will be graded through an automated process.




Reviews
There are no reviews yet.