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

its asking me to do a for loop but no matter what i try I still have it wrong please help

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Safari/537.36 OPR/105.0.0.0

Challenge Information:

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

Hello xhenyvn,

The odd_digits assignment should stay where it was originally (so under the card_number_reversed assignment).
Then for the for loop, the loop itself is fine but you have to print digit (inside the for loop body) instead of printing odd_digits after the loop.

7 Likes

AAA thank you sm it worked !!

2 Likes

Hi HungryBee,

Where is the variable “digit” defined at?

Here it is, he is looping through odd_digits, using digit as the variable name.

But I would strongly advise to make your own topic, this one is old and solved.