Nomor kartu kredit terpecah Python
import re
def cc(pat):
# check for the pattern #### #### #### #### with each '#' being a digit
m=re.match(r'(\d{4})\s(\d{4})\s(\d{4})\s(\d{4})$', pat.strip())
if not m:
return False
# join all the digits in the 4 groups matched,
# turn into a list of ints,
# sum and
# return True/False if divisible by 10:
return sum(int(c) for c in ''.join(m.groups()))%10==0
>>> cc('9384 3495 3297 0123')
False
>>> cc('9384 3495 3297 0121')
True
Xanthous Xenomorph