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

Can anyone help me. I do not know where I went wrong.

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]


# User Editable Region

    for digit in odd_digits:
        sum_of_odd_digits += int(digit)
        print(digit)
    
    sum_of_even_digits = 0
    even_digits = card_number_reversed[1::2]

    for digit in even_digits:
        sum_of_even_digits = int(digit)
        print(digit)
    

# 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/121.0.0.0 Safari/537.36 Edg/121.0.0.0

Challenge Information:

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

1 Like

Loop over the even digits and print each to the console.

So there’s two things to do

  1. Loop
  2. Print

If you are doing anything other than that, I would remove that line of code.

you need to add your digit to sum_of_even_digits, if you overwrite the value of that variable at each loop iteration you are not summing anymore

I am sorry but I need your help…I think my code is running but I got a message saying (You should have print(digit) within the fro loop…

@antoniobray If you have an issue with your code, it’s usually best to create your own topic for it, as otherwise it can cause confusion.

However, in this case, the remedy is simple. You’re just getting a little ahead of yourself. You weren’t yet asked to create a sum_of_even_digits variable, so just remove that line of code for now.

Sorry I am new here…I did not know that I need to create my own topic if the topic exist already. Next time I will do it…
Thanks

1 Like

waoo it works…but with python I got some problem with the indentetion…for example I did know that I can leave a blank line between my loop and the print…it was easy…at least I learn somthing new …Thanks
– removed–

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.