“Número de tarjeta de crédito dividido Python” Código de respuesta

Número de tarjeta de crédito dividido 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

Número de tarjeta de crédito dividido 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

Respuestas similares a “Número de tarjeta de crédito dividido Python”

Preguntas similares a “Número de tarjeta de crédito dividido Python”

Más respuestas relacionadas con “Número de tarjeta de crédito dividido Python” en Python

Explore las respuestas de código populares por idioma

Explorar otros lenguajes de código