CBSE 2026 results are out, Mukul scored a perfect 100/100 in Computer ScienceSee all toppers →

KwickAcademy Course Topics · 7 min · free

Reading, writing, refining and evaluating programs in Python 3

7 min1 KwickClipsFull text belowFree
Next lesson →Kajal Ma'am (MCA), teaching since 2004Remembered in this browser

Four programming skills: read code by tracing it, write code from a plan, refine it by fixing and improving, evaluate it against requirements.

Follows the syllabus of: Edexcel GCSE Computer Science (1CP2)

On screen in this lesson

The four skills

Read: understand what existing code does
Write: create code that solves a problem
Refine: improve code that already works or nearly works
Evaluate: judge how well code meets the requirements

A trace table

Stepmarktotal
Startnone0
Loop 11212
Loop 21830
Loop 31545

Writing: plan first

Read the requirements carefully
Decide the inputs, process and outputs
Choose clear variable names
Write a few lines, run them, then add more

Refining: what to improve

Fix syntax, runtime and logic errors
Replace repeated code with a loop or function
Use meaningful names and helpful comments
Validate input so bad data cannot crash it

Three kinds of error

ErrorMeaningExample
Syntaxbreaks the rulesmissing colon
Runtimecrashes mid-rundivide by zero
Logicruns, wrong answer> instead of >=

Evaluating a program

Does it meet every requirement?
Is the output correct for normal, boundary and invalid data?
Is the code readable, with clear names and comments?
Is it efficient, with no unnecessary repetition?

Quick answers

mark = 40 and the code checks mark > 40. What prints?

Fail. That is a logic error; use >= 40.

Which error runs but gives a wrong answer?

A logic error.

KwickClips from this lesson

Short clips, one idea each. Good for revision the night before.

The full lesson, in text

Hello students, welcome to Kwickprep. Can you understand a program you did not write? Can you make a working program even better? Today we will practise the four skills programmers use every day: reading, writing, refining and evaluating Python 3 programs.

Let us first meet the four skills. Reading means understanding what existing code does, line by line. Writing means creating new code that solves a given problem. Refining means improving code, by fixing errors or making it clearer. Evaluating means judging how well the program meets what was asked.

To read code, trace it, which means following each line and noting how values change. Total starts at zero. The loop takes each mark in turn: twelve, then eighteen, then fifteen. After each step, total becomes twelve, then thirty, then forty five. Finally forty five divided by three prints fifteen point zero, because a single slash always gives a decimal.

A trace table records the value of each variable at every step. At the start, total is zero and mark has no value yet. In loop one, mark is twelve and total becomes twelve. In loop two, mark is eighteen and total becomes thirty. In loop three, mark is fifteen and total becomes forty five.

Now, writing a program from a problem statement. First, read the requirements carefully and underline what must happen. Next, decide the inputs, the processing and the outputs. Then choose clear, meaningful variable names, like marks, not x. Finally, write a few lines, run them, and only then add more.

Here is a written program. The requirement says, print Pass for marks of forty or more, else Fail. The list marks holds three scores, and m takes each score in turn. Greater than or equal to means forty itself passes. So forty five prints Pass, twenty eight prints Fail, and sixty prints Pass.

Refining means making a program better step by step. First, fix any errors: syntax errors, runtime errors and logic errors. Next, replace repeated code with a loop or a function. Then use meaningful names and add helpful comments. Finally, validate input, which means checking the data so bad values cannot crash the program.

While refining, you must recognise three kinds of error. A syntax error breaks the grammar rules of Python, like a missing colon, so the program will not start. A runtime error crashes the program while it runs, like dividing by zero, which gives ZeroDivisionError. A logic error runs without crashing but gives the wrong answer, like using greater than instead of greater than or equal to.

Pause and predict. The rule says forty or more is a pass, and mark is exactly forty. What does result become? It becomes Fail, which is wrong. The program has no syntax error, so this is a logic error. Refine it by changing greater than to greater than or equal to.

Another refinement is removing repeated code. Instead of writing the same if else again and again, we put it in one function called grade. The function returns Pass if m is at least forty, else Fail. Now the loop calls grade for each mark. Forty prints Pass, and thirty nine prints Fail.

Validation stops bad input from crashing a program. Here text stands for what a user typed, and it is a b c. Calling int on a b c would crash with ValueError. So first we ask, is text made only of digits? It is not, so the program politely prints Enter a number.

Evaluating means judging the finished program honestly. First ask, does it meet every single requirement? Next, is the output correct for normal data, boundary data and invalid data? Then, is the code readable, with clear names and comments? Finally, is it efficient, without unnecessary repeated code or extra loops.

Exams may give an algorithm in pseudocode and ask you to write it in Python. The ideas map directly. For each becomes a for loop, if then else becomes if and else, and send to display becomes print. Reading pseudocode is the same skill as reading Python.

Programming exams often give you partly written code to complete, fix or improve. Read the whole task and any given code before typing. Keep the variable names used in the question, so the examiner can follow your work. Run and test often, and save your work regularly. Add short comments that explain what you changed and why.

Let us revise what we learned today. Reading code means tracing it, often with a trace table. Writing starts with a plan of inputs, processing and outputs, then grows step by step. Refining fixes errors, removes repeated code and validates input. You must recognise syntax, runtime and logic errors. Evaluating checks requirements, test data, readability and efficiency. Practise all four skills on every program you write.

Courses that teach this

CourseUnit
Edexcel GCSE GCSE Computer Science (1CP2)Topic 6: Problem solving with programming

Voice-over in this lesson is AI-generated. The script is written and checked by Kajal Ma'am. Boards can revise a syllabus mid-year, so confirm anything you plan around against the official board circular. Keep your passwords, OTPs and ID numbers to yourself — we never ask for them. To reach Kajal Ma'am, use the WhatsApp button; sharing your number there is how we call you back.

Free to watch, no sign-up. Live classes with Kajal Ma'am are the paid course; these lessons stay free either way.

Want a plan that actually fits your board dates?

Ask Kajal Ma'am directly, 20+ years teaching computer science. Free demo class first, no payment.

Talk to Kajal Ma'am on WhatsApp

Or see the Class 12 Computer Science course →

Studying outside India?

We coach CBSE, IGCSE & international students across the globe, one-to-one, in your local time zone.

Visit International →