Understand the idea
A problem you can recognise
You have learned separate tools; now make them cooperate in one useful program. The revision planner should answer a student's practical questions: what have I planned, what have I completed, and can I trust the totals?
Do not begin by adding a login screen or a polished interface. Begin with a tiny session list and calculations you can verify by hand. A small, honest tool is more useful than a large interface built on uncertain numbers.
Understand the idea
Understand the idea
This project combines the core tools into a small revision planner without introducing a paid service or a web framework. Its input is a bounded list of session records; its output is a readable summary of planned and completed minutes. Keep collection processing separate from display so that calculations can be tested independently.
Each record needs a subject, nonnegative integer minutes and a completed boolean. Define those requirements before writing the loop. Reject bad records explicitly instead of silently converting them into zero-minute sessions. A bool is a subclass of int in Python, so type(value) is int is a useful exact-type check when True must not count as one minute. This detail illustrates why validation rules should express the domain precisely.
Start with hard-coded sample data and pure functions. Add JSON import/export only after the calculations and validation pass checks. In browser practice, this means parsing and printing JSON text, not promising durable file storage. A graphical interface, database and network synchronisation are separate future projects. A clear, well-tested console tool is a complete result for this scope.
Work in small checkpoints: validate one record, total two records, calculate completed minutes, then format the report. Verify empty input, all incomplete sessions, all complete sessions and one invalid duration. Keep the first project small enough that you can explain every line without relying on unexplained libraries.
See how it works
Example 1: Total the planned minutes
PYTHON exampleRead the code, then try a change.
Try this example
sessions = [
{"subject": "Python", "minutes": 30, "done": True},
{"subject": "HTML", "minutes": 20, "done": False},
]
planned = sum(session["minutes"] for session in sessions)
print(planned)
Expected output:
ReferenceCompare this with the explanation.
50
The generator expression supplies each duration to sum. The result is planned time, not completed time: completion status has not been used as a filter.
See how it works
Example 2: Count completed minutes
PYTHON exampleRead the code, then try a change.
Try this example
sessions = [
{"minutes": 30, "done": True},
{"minutes": 20, "done": False},
]
completed = sum(session["minutes"] for session in sessions if session["done"])
print(completed)
Expected output:
ReferenceCompare this with the explanation.
30
The condition includes only completed sessions. This is a minutes total, not merely the number of completed records. Keep those measures separate in the final report.
See how it works
Example 3: Validate and report through a function
PYTHON exampleRead the code, then try a change.
Try this example
def report(sessions):
for session in sessions:
value = session["minutes"]
if type(value) is not int or value < 0:
raise ValueError("Invalid duration")
planned = sum(item["minutes"] for item in sessions)
return "Planned minutes: " + str(planned)
print(report([{"minutes": 30}, {"minutes": 20}]))
print(report([]))
Expected output:
ReferenceCompare this with the explanation.
Planned minutes: 50
Planned minutes: 0
This small checkpoint validates duration values and formats a total. The complete assignment additionally validates subject and done fields. The empty list produces a meaningful zero total rather than an invented session.
Understand the idea
Think through the important decisions
Start by writing the record contract in plain language. A session needs a nonempty subject, an exact nonnegative integer duration and a boolean completion flag. Validate required keys before reading them. Remember that True is an instance of int in Python, which is why the exact integer requirement deserves an intentional check.
Next separate validation, calculation and formatting. A planned-minutes function should return a number. A completed-minutes function should count duration only for completed sessions, not merely count completed records. A formatting function should describe already-checked results rather than silently repair bad data.
Build one checkpoint at a time. Validate one session. Total two sessions. Apply completion filtering. Handle an empty list. Only then add JSON interchange and a readable report. At each stage, compare a small input with a result you calculated independently.
An empty plan should produce meaningful zero totals without inventing a session. An invalid duration should be rejected without producing a reassuring but inaccurate report. A mixed plan should distinguish planned minutes, completed minutes and the number of sessions. Those are different measures even when a particular example makes two numbers happen to coincide.
Check your understanding
Check the reasoning
Validate session records and keep pure calculations separate from report formatting.
A matching screenshot or output is one check, not proof that a program is correct for all inputs. Change one input, predict the new result and run again. If the result differs, find the first instruction where your prediction stops matching the program state. Keep that small case as a regression check when you fix the cause.
Spot the mistake
The mistake worth understanding
A successful JSON parse does not validate a session, and a report containing the word "completed" does not prove the completion filter was applied. Keep the data contract and the calculation checks visible. Do not promise permanent storage from this isolated browser exercise.
Your turn
Independent practice
Build a revision planner with validate_session, planned_minutes, completed_minutes and format_report functions. Validate nonempty subject strings, exact nonnegative integer minutes and boolean done fields. Demonstrate empty input, mixed completion states and invalid records. Add JSON text import/export and at least six checks. Do not require a network, real file persistence, a database or third-party packages.
Your turn
Practice hint
Build and test the pure calculations first. Validate required keys before lookup, and keep JSON parsing separate from record validation.
Change it and explain it
Experiment with the first program Build a revision planner with validate_session, planned_minutes, completed_minutes and format_report functions. Validate nonempty subject strings, exact nonnegative integer minutes and boolean done fields. Demonstrate empty input, mixed completion states and invalid records. Add JSON text import/export and at least six checks. Do not require a network, real file persistence, a database or third-party packages. Start by changing one input in this smaller example. Loading it does not execute it.
sessions = [
{"subject": "Python", "minutes": 30, "done": True},
{"subject": "HTML", "minutes": 20, "done": False},
]
planned = sum(session["minutes"] for session in sessions)
print(planned) Open in Practice Loading an example does not run it. Your existing edits are protected by a replacement confirmation.
Your turn
Try a different case
Prepare a short demonstration with an empty plan, a mixed plan, an all-complete plan and invalid records. Explain which earlier lesson justifies each design decision. If you cannot explain a line, simplify it before adding another feature.