Learn How to Work With Numbers and Strings Using Luhn's Algortithm Step 19

def verify_card_number(card_number):
    sum_of_odd_digits = 0
    card_number_reversed = card_number[::-1]
    odd_digits = card_number_reversed[::2]
**for variable in odd_digits:   **
**    print(variable)**

    
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()

I’m not seeing how to correctly solve this. On the forums I’ve seen, this is the syntax I need to do the loop it’s asking me to do, but I don’t understand how to stop getting errors. Perhaps I need to define “variable?”

Hi there and welcome to our community!

For future reference: If you need help with a particular challenge, it is best to click on the Help button, which appears after you have submitted incorrect code three times.
This will create a forum post which automatically includes your full code, a direct link to the challenge and an opportunity for you to describe your issue in detail.

I have formatted your post so that your code displays correctly, and have included a link to the step.

Your code for this step is actually fine (once you remove the asterisks), as long as it is indented correctly. The for loop should be indented in line with the code directly above it, with the print command indented four spaces inside the for loop.
You can use the name variable if you wish, but it’s generally a good idea to use a name which relates to what you’re iterating (e.g. digit).

Thank you so much, this challenge was driving me crazy.

This is my first time using the help link and I couldn’t figure out how to make it pop up like you’re talking about, so thank you for that tip, too.

2 Likes

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