Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.32 KB | None | 0 0
  1. # in: string
  2. # out: boolen
  3. def is_valid(num):
  4. digits = [int(n) for n in num]
  5. ttl = 0
  6. parity = len(digits) % 2
  7. for key, value in enumerate(digits):
  8. if key % 2 == parity:
  9. value *= 2
  10. if value > 9:
  11. value -= 9
  12. ttl += value
  13. rv = total % 10 == 0
  14. return rv
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement