
Capstone: Your Own Lantern
The Lantern Network is online. Look back at how far you've come. You
started with a single print("Hello, Pythonia!"). Since then you've
learned loops, functions, files, classes, generators, algorithms,
types, tests, regex, decorators, async and packaging.
Every lesson so far told you what to build. This one doesn't. Real developers get a short spec (a description of what's wanted) and design the code themselves. That's your graduation project.
The spec
Build a small tracker for something you care about. Some ideas:
- minutes of music or sport practice per day
- books you've read, with ratings
- plants and when you last watered them
- high scores for a game you play with friends
- pocket money: what came in and what went out
Your tracker should store some data, answer questions about it (a total, a best, a search...) and refuse bad input with an error.
How it's checked
There's no single right answer, so the checker looks at quality, not exact output. It checks that you have:
- Your own design: one class with 2 or more public methods, or
3 or more functions (not counting
main). - Docstrings and type hints on every public function, class and
method (public means the name doesn't start with
_). Every parameter exceptselfneeds a hint, plus a return hint (-> int,-> None...). - Real tests: a
unittest.TestCaseclass whose test methods use your code, call aself.assert...method, and all pass. - A
main()that runs with no arguments and prints a short demo.
class TestTracker(unittest.TestCase):
def test_total(self):
t = Tracker()
t.add("mon", 20)
self.assertEqual(t.total(), 20)
Don't call unittest.main(): the checker runs your tests for you.
Assignment
- Plan. Pick what to track. In the top docstring, replace the
TODOwith one sentence saying what your tracker does. - Build. Write a class with at least 2 public methods (or 3+ functions). Give each one a docstring and type hints.
- Guard. Make at least one method or function raise
ValueErrorfor bad input (like negative minutes). - Test. Write at least 3 test methods in your
TestCaseclass. Include one that usesself.assertRaises(ValueError). Run your code and make sure every test passes. - Demo. Make
main()create your tracker, add some data and print a few results. - Revise. Real projects grow. Add one new feature (an average, a search, a "best" item...) and a 4th test for it. Run everything again.
When these checks pass, you graduate from the Lantern Guild as a Master Lanternwright. Pip's final tip: keep a project going. Automate something in your own life, read other people's code, and share what you build. Every program you write lights another lantern somewhere.
- Plan. Pick what to track. In the top docstring, replace the
TODOwith one sentence saying what your tracker does. - Build. Write a class with at least 2 public methods (or 3+ functions). Give each one a docstring and type hints.
- Guard. Make at least one method or function raise
ValueErrorfor bad input (like negative minutes). - Test. Write at least 3 test methods in your
TestCaseclass. Include one that usesself.assertRaises(ValueError). Run your code and make sure every test passes. - Demo. Make
main()create your tracker, add some data and print a few results. - Revise. Real projects grow. Add one new feature (an average, a search, a "best" item...) and a 4th test for it. Run everything again.
When these checks pass, you graduate from the Lantern Guild as a Master Lanternwright. Pip's final tip: keep a project going. Automate something in your own life, read other people's code, and share what you build. Every program you write lights another lantern somewhere.
Press Run to try your code, then Check to test it.