Back to Freecodecamp

Step 20

curriculum/challenges/english/blocks/learn-how-to-work-with-numbers-and-strings-by-implementing-the-luhn-algorithm/65687b182c2a8fb1470e0b97.md

latest1.2 KB
Original Source

--description--

Within the for loop, use the += operator to add the digit to the sum_of_odd_digits variable.

Doing this your script throws a TypeError because you are trying to add a string to an integer, but don't worry, you will learn more about how to make it work in the next step.

--hints--

You should have sum_of_odd_digits += digit within the for loop.

js
const transformedCode = code.replace(/\r/g, "");
const verify_card_number = __helpers.python.getDef("\n" + transformedCode, "verify_card_number");
const { function_body } = verify_card_number;

assert.match(function_body, /sum_of_odd_digits\s*\+=\s*digit/);

--seed--

--seed-contents--

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