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

The message i am getting is just the message that an error with my code is present and i don’t know what to do further.

I seemingly did all that the instructions asked and it is just an issue with the placement or possibly the wording of the for loop.

Your code so far


# User Editable Region

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

for digit in odd_digits:
    odd_digits = card_number_reversed[::2]
    print(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; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

Hi @conwhiteside,

You shoud reset this challenge before continuing. You moved a key line from the start of the challenge into the for loop. And then placed the for loop outside of the function definition.

def verify_card_number(card_number):
    sum_of_odd_digits = 0
    card_number_reversed = card_number[::-1]
    # this line was moved into a for loop that exists outside of the function
    odd_digits = card_number_reversed[::2]

Keep in mind that indentation matters in Python. Keep the for loop inside of the function through indentation matching. Since your for loop has no indentation, it is a part of the main script itself.

You’ll need to also make sure you that odd_digits is created before you try to loop over it. And then be sure to only loop over the digits inside of odd_digits and don’t try to set its value to something different inside of the loop.

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.