“Nomor kartu kredit terpecah Python” Kode Jawaban

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

Nomor kartu kredit terpecah Python

def check(S): 
    if len(S) != 19 and S[4] != '' and S[9] != '' and S[14] != '':
        return False                # checking if the format is correct

    S = S.replace(" ",'')         # Taking away spaces in the string
    if not S.isdigit():
        return False             # checking that the string has only numbers

    L = []            
    for i in S:
        i = int(i)                # Making a list out of the string and converting each character to an integer so that it the list can be summed 
        L.append(i)
    if sum(L)//10 != 0:        # checking to see if the sum of the list is divisible by 10
        return False
Xanthous Xenomorph

Jawaban yang mirip dengan “Nomor kartu kredit terpecah Python”

Pertanyaan yang mirip dengan “Nomor kartu kredit terpecah Python”

Lebih banyak jawaban terkait untuk “Nomor kartu kredit terpecah Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya