Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_valid(id: str):
- """
- Calculates whether an ID number if valid
- """
- if len(id) != 9:
- return False
- _sum = 0
- for i in range(8):
- if i % 2 == 0:
- weight = 1
- else:
- weight = 2
- value = int(id[i]) * weight
- while value > 9:
- value = value // 10 + value % 10
- _sum += value
- if _sum % 10 == 0:
- return int(id[8]) == 0
- else:
- return int(id[8]) == 10 - (_sum % 10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement