Skip to content

Instantly share code, notes, and snippets.

@ZechCodes
Last active October 25, 2020 02:48
Show Gist options
  • Save ZechCodes/daf4e2e6780306f0ed01f6439d282736 to your computer and use it in GitHub Desktop.
Save ZechCodes/daf4e2e6780306f0ed01f6439d282736 to your computer and use it in GitHub Desktop.
Challenge 138 - Length of Worm

Challenge 138 - Length of Worm

Given a string worm create a function that takes the length of the worm and converts it into millimeters. Each - represents one centimeter.

Examples

worm_length("----------") ➞ "100 mm."

worm_length("") ➞ "invalid"

worm_length("---_-___---_") ➞ "invalid"

Notes

  • Return "invalid" if an empty string is given or if the string has characters other than -.
import unittest
def worm_length(worm: str) -> str:
return "" # Put your code here!!!
class Test(unittest.TestCase):
def test_1(self):
self.assertEqual("100 mm.", worm_length("----------"))
def test_2(self):
self.assertEqual("invalid", worm_length(""))
def test_3(self):
self.assertEqual("invalid", worm_length("---_-___---_"))
def test_4(self):
self.assertEqual("60 mm.", worm_length("------"))
def test_5(self):
self.assertEqual("invalid", worm_length("iwheguawhpvpaiehpiuwwega"))
def test_6(self):
self.assertEqual("invalid", worm_length("QWERTYUIOPASDFGHJKL"))
def test_7(self):
self.assertEqual("120 mm.", worm_length("------------"))
if __name__ == "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment