String Exercises
Parse a workshop code at the first hyphen and keep the remaining suffix intact, even when the suffix contains another hyphen.
Understand the idea
Write your own solution before opening the worked answer. Predict the output from the supplied values, then compare the actual result. Check both an ordinary case and the boundary described below; a passing example is more useful when you can explain why it passes.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
Your task
Parse a workshop code at the first hyphen and keep the remaining suffix intact, even when the suffix contains another hyphen.
Show the worked solution
prefix, separator, suffix = "PY-evening-02".partition("-")
print(prefix, suffix)
Check the result
The prefix is PY and the suffix is evening-02.
Test one more case
Handle a code with no hyphen and decide whether to reject or retain it.