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

I have tried my best to fix it but i cant!

Use a for loop to iterate over each digit in the odd_digits list. Move your print call from the previous step into the for loop, and change it to print each digit.

My code so far


# User Editable Region

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

for odd_digits
    

# 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 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36

Challenge Information:

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

1 Like

Hello @MrSanyi

Until this point you had this:

print(odd_digits)

Now, it is asking to loop over the odd_digits and to print each digit.
If I have a list of values in Python and I want to iterate over them and print each member I do:

for item in items:
    print(item)

Make sure you place the for loop inline with odd_digits inside the function.

1 Like

I didn’t realise that one can set a new variable within the for loop, i.e. item in items where item did not exist earlier in the code. Something to remember