Learn How to Work with Numbers and Strings by Implementing the Luhn Algorithm - Step 32

Tell us what’s happening:

I am stuck at this step can anyone share your expertise to solve this issue and move ahead of the problem

Your code so far

def verify_card_number(card_number):
    sum_of_odd_digits = 0
    card_number_reversed = card_number[::-1]
    odd_digits = card_number_reversed[::2]

    for digit in odd_digits:
        sum_of_odd_digits += int(digit)

    sum_of_even_digits = 0
    even_digits = card_number_reversed[1::2]
    for digit in even_digits:
        number = int(digit) * 2
        if number >= 10:
            number = (number // 10) + (number % 10)
        sum_of_even_digits += number

# User Editable Region

    total = sum_of_odd_digits + sum_of_even_digits
    print(total)


# User Editable Region

def main():
    card_number = '4111-1111-4555-1142'
    card_translation = str.maketrans({'-': '', ' ': ''})
    translated_card_number = card_number.translate(card_translation)

    verify_card_number(translated_card_number)

main()

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36

Challenge Information:

Learn How to Work with Numbers and Strings by Implementing the Luhn Algorithm - Step 32

Hi there! :waving_hand:

You’re close! But you’re missing an important part of the lesson instructions:

Return the result of comparing 0 to total modulo 10.

Also, just to clarify — we’re not allowed to give the full solution directly. The idea is to help you understand so you can fix it on your own and learn through the process

Well, you should use a return statement that checks whether total modulo 10 is equal to 0.

i am unable to get what exactly you want me to do here can you please elaborate it a little

I understand it can be a bit confusing. Here’s a hint to help you move forward:

You’re already calculating the total correctly, which is great! Now, the next step is to check if the number is divisible by 10.

Here’s how you can do it:

  • Use the modulo operator (%) to find the remainder when dividing total by 10.
  • If the remainder equals 0, it means the number is divisible by 10.

That’s exactly what the lesson is asking for at this step! :blush:

thanks the issue is solved

1 Like