← Back to challenges

Length of Worm

PythonHardstrings

Instructions

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 -.

python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: Preventing the Collapse of the Universe