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

translated_card_number = “4112-2112-2113”
translation_table = translated_card_number.maketrans({‘4’: ‘1’, ‘1’: ‘2’, ‘-’: ‘’, ‘2’: ‘1’, ‘3’: ‘’})
translated_card_number = translated_card_number.translate(translation_table)
print(translated_card_number)

Your code so far


/* User Editable Region */

translated_card_number = "4112-2112-2113"
translation_table = translated_card_number.maketrans({'4': '1', '1': '2', '-': '', '2': '1', '3': ''})
translated_card_number = translated_card_number.translate(translation_table)
print(translated_card_number)

/* User Editable Region */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36

Challenge Information:

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

Hello!

You don’t need to change the variable names, the maketrans () method or add a print() function (yet!).
You only have to change line 4 for the solution with the variable and method names exactly like given in the task.

If you need further help, feel free to ask.

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