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

Tell us what’s happening:

I am unable to tell what I am getting wrong, I believe it is the for loop, possibly line 4. When I submit it says “Your code raised an error before any tests could run. Please fix it and try again.”

I also think it might be the print, being it might need digit, or odd_digits

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 odd_digits:
            odd_digits = card_number_reversed[::]
            print(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; Ubuntu; Linux x86_64; rv:121.0) Gecko/20100101 Firefox/121.0

Challenge Information:

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

A few things to address here:

  1. The format of your for loop is incorrect. You can review how to make a for loop: https://www.w3schools.com/python/python_for_loops.asp
fruits = ["apple", "banana", "cherry"]
for x in fruits:
  print(x) 
  1. If you are going to iterate over odd_digits in the for loop, you need to assign odd_digits first.

  2. The print won’t work because you never define a variable called digits so it doesn’t exist. This is slightly related to point 1.

You can re-write your code in the format of the example given above.