Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # in: string
- # out: boolen
- def is_valid(num):
- digits = [int(n) for n in num]
- ttl = 0
- parity = len(digits) % 2
- for key, value in enumerate(digits):
- if key % 2 == parity:
- value *= 2
- if value > 9:
- value -= 9
- ttl += value
- rv = total % 10 == 0
- return rv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement