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

Tell us what’s happening:

Can someone explain to me what i am doing wrong.

Your code so far


# User Editable Region

def main():
    card_number = '4111-1111-4555-1142'
  card_translation = str.maketrans({"": " "})
    

# User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/137.0.0.0 Safari/537.36

Challenge Information:

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

There are 3 issues with your code

  1. Indendation error - make sure both lines under main method have same tab spaces
  2. you should pass mapping of characters with what you want to replace like following card_translation = str.maketrans({“-”: “”})
  3. user translate method on string class and pass card translation like below
    clean_card = card_number.translate(card_translation);

So final code will be

MOD EDIT SOLUTION REMOVED

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.

1 Like