anonymize_4.py 382 B

12345678910111213141516171819202122
  1. def validate_nhs_number(num):
  2. s = str(num)
  3. if len(s) != 10:
  4. return False
  5. tot = 0
  6. for i in range(9):
  7. dig = int(s[i])
  8. tot += dig * (10-i)
  9. tmp = tot % 11
  10. if tmp == 0:
  11. checksum = 0
  12. else:
  13. checksum = 11 - (tot % 11)
  14. if checksum == 10 or checksum != int(s[9]):
  15. return False
  16. else:
  17. return True