Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Last active September 7, 2020 13:33
Show Gist options
  • Save ZechCodes/f6a899731ea18cea3ead4cfb93edea55 to your computer and use it in GitHub Desktop.
Save ZechCodes/f6a899731ea18cea3ead4cfb93edea55 to your computer and use it in GitHub Desktop.
Challenge 100 - Hiding the Card Number

Challenge 100 - Hiding the Card Number

Write a function that takes a credit card number and only displays the last four characters. The rest of the card number must be replaced by ************.

Examples

card_hide("1234123456785678") ➞ "************5678"

card_hide("8754456321113213") ➞ "************3213"

card_hide("35123413355523") ➞ "**********5523"

Notes

  • Ensure you return a string.
  • The length of the string must remain the same as the input.
import unittest
def card_hide(card_number: str) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual("************5678", card_hide("1234123456785678"))
def test_2(self):
self.assertEqual("************3213", card_hide("8754456321113213"))
def test_3(self):
self.assertEqual("**********5523", card_hide("35123413355523"))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment