INTRODUCTION
A check digit is a form of redundancy check used for error detection on identifi-
cation 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
Copyright By PowCoder代写 加微信 powcoder
digits computed by an algorithm from the other digits (or letters) in the sequence
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.
Consider the following algorithm for computing check digit for students.
• First, set sum
= 0. Student-id consists of six digits.
• For each digit in the student number that has odd position(first, third and
fifth) take the digit and add it to the sum
• For each digit in the student number that has even position (second, forth
and sixth) take twice the digit. If the 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 sum.
• The one digit number, which when added to the sum results in a multiple of
10, is the check digit.
Take an example of student number of 167912
7+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. This is written
as 167912-5. That is called the student-id.
PROJECT SPECIFICATIONS
The main goal of this project, is to determine the digit that is missing from a
student-id or if no digit is missing to determine whether it the student-id is valid
or not. Write a function named check_digits(s) which takes a strings as input
The input string represents student-id which will be of the form
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:
• If there is no question mark: Print VALID if the check digit is correct.
Otherwise print INVALID.
• If check digit position is question marked: Compute the check digit
and print the whole student-id (with the correct check digit present)
• If 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).
EXAMPLE INPUTS AND OUTPUTS
1. print (check_digits (“167912-5”)) prints VALID.
2. print (check_digits (“167912-3”)) prints INVALID.
3. print (check_digits(“167912-?”)) prints 167912-5.
4. print (check_digits(“1679?2-5”)) prints 167912-5
5. print (check_digits (“139503-7”)) prints VALID.
6. print (check_digits(“13?503-7”)) prints 139503-7
7. print (check_digits(“?39503-7”)) prints 139503-7
8. print (check_digits (“144256-5”)) prints VALID.
9. print (check_digits (“344256-5”)) prints INVALID.
10. print (check_digits (“1?4256-5”)) prints 144256-5.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com