
Checkpoint
Checkpoint: The Ship's Register
A tired harbour clerk typed a ship into the register. The
line is messy: odd spaces, small letters, and everything
squashed together with | signs. Let's tidy it up!
This checkpoint uses the whole chapter: split, indexes,
slices, strip, title, upper, int() and f-strings.
One handy fact: int(" 12 ") gives 12. It ignores spaces
around the digits.
Assignment
Work from entry (don't type the answers yourself):
- Set
partstoentrysplit on"|". - Set
nameto the first part, stripped, in title case. Here that's"Captain Ada". - Set
portto the second part, stripped, in UPPERCASE. Here that's"MOONWELL". - Set
codeto the first 3 letters ofport("MOO"). - Set
crewto the third part as a number, usingint(). - Print this line with an f-string:
Captain Ada sails from MOONWELL (MOO) with 12 crewWork from entry (don't type the answers yourself):
- Set
partstoentrysplit on"|". - Set
nameto the first part, stripped, in title case. Here that's"Captain Ada". - Set
portto the second part, stripped, in UPPERCASE. Here that's"MOONWELL". - Set
codeto the first 3 letters ofport("MOO"). - Set
crewto the third part as a number, usingint(). - Print this line with an f-string:
Captain Ada sails from MOONWELL (MOO) with 12 crewmain.py Python sleeping
Press Run to try your code, then Check to test it.