A University of Helsinki student number is a sequence of nine digits. The first digit is and the last digit is a check value that allows checking for typos in the student number.
The check value is obtained by summing up the other digits multiplied by the values in the left-to-right order. If the sum is a multiple of , the check digit is . Otherwise, the check digit is the distance of the sum to the next multiple of .
For example, if the student number is , the sum is . The next multiple of is and the distance to that is . Thus the last digit of the student number is .
In a file student.py
, implement the function check_number
that reports if the parameter is a valid student number. The function should return True
or False
.
Your function will be tested using many different sequences of digits.
def check_number(number): # TODO if __name__ == "__main__": print(check_number("012749138")) # False print(check_number("012749139")) # True print(check_number("013333337")) # True print(check_number("012345678")) # False print(check_number("012344550")) # True print(check_number("1337")) # False print(check_number("0127491390")) # False