You must write a function control (p_nr) that calculates and returns the control digit in a 10-digit social security number if you send in the first 9 digits in the form of a string. The rules for calculating the check digit in a social security number are as follows: The numbers are multiplied alternately by 2 and 1 and then the products are summed. For a two-digit product, the sum of its numbers is calculated. The sum is then subtracted from the nearest higher tens to obtain the check digit.
Python task
You must write a function control (p_nr) that calculates and returns the control digit in a 10-digit social security number if you send in the first 9 digits in the form of a string.
The rules for calculating the check digit in a social security number are as follows:
The numbers are multiplied alternately by 2 and 1 and then the products are summed. For a two-digit product, the sum of its numbers is calculated. The sum is then subtracted from the nearest higher tens to obtain the check digit.
To calculate the check digit for the social security number with the first 9 digits 811218987, perform the following setup:
8 1 1 2 1 8 9 8 7
2 1 2 1 2 1 2 1 2
16 1 2 2 2 8 18 8 14
1 + 6 + 1 + 2 + 2 + 2 + 8 + 1 + 8 + 8 + 1 + 4 = 44
The check digit is 50-44 = 6
# test
personal_number = input ()
control_digit = control(personal_number)
print(control_digit)
Step by step
Solved in 3 steps with 1 images