-2

Hey guys python noobie here. I'm trying to determine which type of credit card a user has and whether it's valid or not. For the following example, Visa cards start with the number 4 and both cards would be valid because they both start with 4. If there are zeros in front, you would skip them. Is there a built in function to bypass a number or do I have to type in every case scenario? Thank you for your time.

Example:

#VISA 0004222222222222 valid
#VISA 4111111111111111 valid

Luhns Algorithm

def calculation( creditNumber ): length = len( creditNumber ) oddSum = 0 evenSum = 0

if ( length == 0 ):
    return 0

else:
    if length % 2 == 0:
        last_number = int( creditNumber[-1])
        evenSum = evenSum + last_number

        return evenSum + calculation( creditNumber[:-1] )

    else:
        last_number = int( creditNumber[-1] )
        last_number = 2 * last_number
        addSum = last_number // 10 + last_number % 10
        oddSum = oddSum + addSum

        return oddSum + calculation( creditNumber[:-1] )

def luhnsCheck():
    creditNumber = input ( "What is your credit card number?" )

    #Check to see which type of credit card the user has

    # American Express starts with 34 or 37 
    if creditNumber[0-15] 


    # Discover starts with 6011

    # MasterCard starts with 51 or 52 or 53 or 54 or 55

    # VISA starts with 4

    creditcard_number = calculation( creditNumber )

    # Valid Card
    if creditcard_number % 10 == 0:
        print( "Valid card" )


    # Invalid Card
    else:
        print( "We do not accept that kind of card" )

luhnsCheck()

bam
  • 1
  • 2

1 Answers1

-1

You could copy then number and put that number in a list. Then if the first number is zero then remove it from the list. Repeat this until there is no zero in front.