Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Created December 30, 2020 02:41
Show Gist options
  • Save ZechCodes/e5b5c7c013b3b03486703f9373b0f450 to your computer and use it in GitHub Desktop.
Save ZechCodes/e5b5c7c013b3b03486703f9373b0f450 to your computer and use it in GitHub Desktop.
Challenge 154 - Validate Pin

Challenge 154 - Validate Pin

Create a function to test if a string is a valid pin or not.

A valid pin has:

  • Exactly 4 or 6 characters.
  • Only numerical characters (0-9).
  • No whitespace.

Examples

valid("1234") ➞ True

valid("45135") ➞ False

valid("89abc1") ➞ False

valid("900876") ➞ True

valid(" 4983") ➞ False

Notes

  • Empty strings should return False when tested.
import unittest
def validate_pin(pin: str) -> bool:
return False # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual(validate_pin("123456"), True)
def test_2(self):
self.assertEqual(validate_pin("4512a5"), False)
def test_3(self):
self.assertEqual(validate_pin(""), False)
def test_4(self):
self.assertEqual(validate_pin("21904"), False)
def test_5(self):
self.assertEqual(validate_pin("9451"), True)
def test_6(self):
self.assertEqual(validate_pin("213132"), True)
def test_7(self):
self.assertEqual(validate_pin(" 4520"), False)
def test_8(self):
self.assertEqual(validate_pin("15632 "), False)
def test_9(self):
self.assertEqual(validate_pin("000000"), True)
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment