CKTIS / Learning and practice
Predict, change, explain: how to learn programming through practice
Turn reading code into independent practice. A Python example, edge cases, debugging and a manageable first-week plan help you check what you understand.

An example can look obvious while you are reading it and become surprisingly difficult when you try to write it yourself. That gap gives you a useful starting point. Instead of collecting more explanations, take one short program, predict what it will do, change something and explain the result.
We will practise that routine with a small Python program that adds up study time. You can trace every step on paper before running it. The aim is to understand a few decisions well enough to make them yourself, then turn that understanding into a manageable first week of practice.
Choose a result you can check
“Learn programming” is too large a task for one sitting. “Add three study sessions and calculate the minutes left before an hour” gives you a result you can check. You know the input, the calculation and the answer you expect to see.
Write those three things down before opening an editor. Our inputs are whole minutes, all zero or greater. We want a total and a remaining time that never drops below zero. These are decisions about the problem, not Python syntax.
Predict, change, explain
First, predict the output without running the program. Write the actual numbers, including their order. If you cannot decide, identify the instruction that makes you hesitate. That is a much more useful question than “Why do I not understand this?”
Next, run the code and compare the result with your prediction. Agreement is useful, but ask how you reached it. Guessing the right answer is different from following the calculation.
Then change one thing: an input value or the target. Predict again before running. Keeping the change small makes its effect easier to follow.
Finally, explain what happened in your own words. “Each session was added to the total” is a good beginning. Add enough detail that another person could reproduce your reasoning without seeing the output.
Follow a small Python program
Suppose three practice sessions lasted 12, 18 and 25 minutes. Our target is 60 minutes. Read the program and predict both printed values:
minutes = [12, 18, 25]
target = 60
total = 0
for session in minutes:
total = total + session
remaining = max(target - total, 0)
print(total)
print(remaining)
The output is:
55
5
The list minutes stores the session lengths. total starts at zero because nothing has been added yet. The loop takes one value at a time and updates the running total: first 12, then 30, then 55.
The indented instruction belongs to the loop. The calculation of remaining comes after the loop, so it uses the completed total. target - total gives 5. The function max selects the larger of 5 and 0, so the remaining time is 5.
Try describing the assignment total = total + session as an action: calculate the new sum using the old total, then store that sum as the new total. It is an update, not a claim that two mathematical expressions are always equal.
Change the data and test your assumptions
Start each experiment from the original list [12, 18, 25]. For the first, append 5: the total becomes 60 and the remaining time becomes 0. For the second, restore the original list and append 15: the answers become 70 and 0. These are separate experiments.
In the second case, subtraction alone produces -10. Choosing the greater of -10 and 0 means that this program reports no minutes remaining. It does not report how far you exceeded the target. That is a deliberate choice about what the result represents.
Now use an empty list. The loop has no values to visit, so the total stays 0 and 60 minutes remain. Compare that with [0]: the output is the same, although the recorded sessions differ.
We assumed nonnegative whole minutes. The program does not validate that assumption. max limits the displayed remainder; it does not check whether every input describes a sensible session.
When the result surprises you
Keep your prediction beside the actual output. Trace the total after each session and find the first place where your notes differ from the program. A temporary print(total) inside the loop can show those intermediate values. Remove it after the investigation so the final output has two lines again.
If Python reports an error, read the message and the indicated line before changing anything. Check spelling and indentation. Changing several lines at once can hide which change solved the problem.
There are also mistakes that produce no error message. Setting total to zero inside the loop would erase the previous sum each time. The program might run, but it would answer a different question. Use a simple example and your handwritten trace to spot the difference.
Build a realistic first week
For the first session, run the original example, label the input and output, and explain the three intermediate totals. Stop when you can follow the calculation without guessing.
In the next session, return before reading the solution. Recreate the list and the loop from memory. If you get stuck, consult only the missing part, then close the example and try again. This shows which step needs more practice.
Use another session for the three experiments: reaching the target exactly, exceeding it and providing no sessions. Keep predictions and actual results together. Later, change the target and explain how that affects both outputs.
At the end of the week, write the program again and describe one decision you made. You can spread these sessions across the days available to you. A short, specific task is easier to resume than an unfinished promise to study for hours.
Leave evidence and a next step
Save the working code with two short notes: what you can now explain and what still needs checking. “I understand why the total begins at zero; I still confuse indentation” points towards a useful next session.
To extend the exercise, decide whether you want to show minutes beyond the target as well. Describe that result and predict it for the original data before writing new code. You do not need the solution immediately; defining the question is part of the work.
If you need a structured route through variables and loops, look at the beginner Python course, or choose a starting point from the courses. For now, take one action: restore the original list, hide the output and explain why the two answers will be 55 and 5.