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

Tell us what’s happening:

in the for loop
for digit in (odd_digits):
print(digit)

on the console the numbers appeared in the correct order but the code checker returned you should have !1(Undifined within the for loop .)

can someone explain what is the diffrence between the code above above and this one, and what is !1. thanks
for digit in odd_digits:
print(digit)

Your 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 digit in (odd_digits):
        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/134.0.0.0 Safari/537.36

Challenge Information:

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

Hello there!

I think the issue you’re encountering is related to the syntax of how you’re using for loops in in Python.

You’re passing the iterable to the loop. In the first version, you’re wrapping odd_digits inside parentheses like this: for digit in (odd_digits):

In short, you only need to pass it directly to the loop, without the parentheses.

The error you’re seeing (“!1 Undefined within the for loop”) s probably related to the syntax used for the loop. When you wrap odd_digits in parentheses, Python doesn’t expect that, and it might be confusing the code checker tool.

Try using the second loop directly like this:

code removed by moderator

I hope this helps! : )

where do you see this?

to pass please remove the round parenthesis from the loop definition

hi @clayebba1

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. How to Help Someone with Their Code Using the Socratic Method

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.