Python - Numero de tarjeta

 
Vista:

Numero de tarjeta

Publicado por Angel (7 intervenciones) el 16/07/2019 03:18:36
Hola, este ejercicio me esta tomando muchisimo. alguien que me pueda ayudar? si es de la CDMx podríamos tener una clase.


def verify(number) : # do not change this line!

# write your code here so that it verifies the card number

# be sure to indent your code!

return True # modify this line as needed

input = "5000-0000-0000" # change this as you test your function
output = verify(input) # invoke the method using a test input
print(output) # prints the output of the function
# do not remove this line!

y estas son las condiciones


1. The first digit must be a 4.
2. The fourth digit must be one greater than the fifth digit; keep in mind that these are
separated by a dash since the format is ####-####-####.
3. The sum of all digits must be evenly divisible by 4.
4. If you treat the first two digits as a two-digit number, and the seventh and eighth digits
as a two-digit number, their sum must be 100.


algo de guía por favor?
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
sin imagen de perfil
Val: 156
Ha disminuido 1 puesto en Python (en relación al último mes)
Gráfica de Python

Numero de tarjeta

Publicado por Andrés (55 intervenciones) el 16/07/2019 04:02:49
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
def verify(card_number):
 
    digits = [int(c) for c in card_number if c.isdigit()]
 
    # The first digit must be a 4.
    if 4 != digits[0]:
        return False
    # The fourth digit must be one greater than the fifth digit
    if digits[3] +1 != digits[4]:
        return False
    # The sum of all digits must be evenly divisible by 4
    if 0 != sum(digits)%4:
        return False
    # If you treat the first two digits as a two-digit number,
    # and the seventh and eighth digits as a two-digit number, their sum must be 100.
    first_group  = digits[0] * 10 + digits[1]
    second_group = digits[5] * 10 + digits[6]
    if 100 != first_group + second_group:
        return False
 
    return True
 
input = "5000-0000-0000" # change this as you test your function
output = verify(input) # invoke the method using a test input
print(output) # prints the output of the function
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Numero de tarjeta

Publicado por Angel (7 intervenciones) el 23/07/2019 22:37:26
me marca este error.

estas en la cdmx? te puedo mandar un correo haber si pudieramos tener una clase?
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 37
Ha disminuido su posición en 3 puestos en Python (en relación al último mes)
Gráfica de Python

Numero de tarjeta

Publicado por Thanatos (9 intervenciones) el 24/07/2019 02:49:29
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
import re
 
def verify(number):
    '''
    Verifies a credit card number.

    number: str
    return: bool
    '''
    pattern = re.compile(r"\d{4}-\d{4}-\d{4}")
    if not pattern.match(number):   # checks the input format.
        return False
 
    digits = [int(char) for char in number if char.isdigit()]
 
    if digits[0] != 4:              # rule #1.
        return False
    if digits[3] - digits[4] != 1:  # rule #2.
        return False
    if sum(digits) % 4 != 0:        # rule #3.
        return False
 
    addition = (digits[0] + digits[6]) * 10 + (digits[1] + digits[7])
    if addition != 100:             # rule #4.
        return False
 
    return True
 
 
INPUT = "5000-0000-0000"            # change this as you test your function.
OUTPUT = verify(INPUT)              # invoke the method using a test input.
print(OUTPUT)                       # prints the output of the function.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar