Digital Technologies · Programming in Python
Coding in Python
Write real Python – print, variables, loops and if statements – and have each program checked automatically.
- Curriculum: Digital Technologies, Programming in Python
- Class: SSS 1 – SSS 3
- For WAEC, NECO practicals
- Readings, table
- Quiz with answers explained
Start this experimentAll Digital Technologies experiments
Aim
To write, run, test and debug simple Python programs using variables, arithmetic, loops and selection.
Apparatus
- This code editor (works offline)
- Optional: Python installed on a computer
Theory
- print("Hello") displays text; print(3 * 4) displays 12.
- A variable stores a value: price = 500.
- A for loop repeats: for i in range(1, 6): runs with i = 1, 2, 3, 4, 5.
- if / elif / else chooses what to do. Lines inside a loop or an if are indented by 4 spaces.
- sum(list), len(list) and round(x, 1) are built in.
This editor runs a teaching subset of Python offline. It supports variables, numbers, strings, f-strings, lists, if/elif/else, for and while loops and common built-in functions, but not def, import or input().
Procedure
- Choose a task and read it carefully.
- Write your program in the editor and press Run to see the output.
- Read any error message: it tells you the line and the kind of mistake.
- Press Check task to test your program automatically.
- Work through all six tasks.
What you do in the virtual lab
Set up the apparatus on screen, take readings and record them in a table (Task; Lines of code; Result). Simulated instruments give slightly different readings each time, as real ones do. Finish with a short quiz; every answer is explained.
Teachers can set the experiment for a class, see each student’s results and use it as a WAEC- or NECO-style practical paper in exam practice.
Practice questions
What does this print? x = 5 then print(x * 2 + 1)
- 15
- x * 2 + 1
- 11
- 5 * 2 + 1
Show the answer
C. 11 Multiplication first: 5 × 2 = 10, then + 1 = 11.
How many times does the body of for i in range(3): run?
- 3
- 2
- 4
- 0
Show the answer
A. 3 range(3) gives 0, 1 and 2 – three values.
Why does print("Age: " + 15) give an error?
- print cannot show numbers
- The quote marks are wrong
- 15 is too big
- You cannot join a string and a number with + without converting the number first
Show the answer
D. You cannot join a string and a number with + without converting the number first Use print("Age: " + str(15)) or print("Age:", 15).
Related Digital Technologies experiments
- Logic gates and truth tablesSwitch the inputs of AND, OR, NOT, NAND, NOR and XOR gates and build each truth table.
- Binary, octal and hexadecimalFlip eight bit-switches to see how computers store numbers, then hit target values in binary.
- Programming a robot: sequence and loopsWrite a program of moves and turns to steer a robot to its goal, then shorten it with a loop.
- How strong is a password?Test made-up passwords, measure their strength in bits and see how long an attacker would need to guess them.
- Spreadsheet formulas and functionsUse cell references, SUM, AVERAGE, MAX and IF to complete a shop sales record and a class result sheet.
- Train a simple AITeach a computer to tell ripe plantain from unripe by giving it labelled examples, then test how accurate it is.