◇ OpenCyber Academy
Bachelor's · Chapter 3 · English

Chapter 3 — Programming I

Open, free learning for anyone who wants to protect people and technology. No account is required to read this text or its worked answers.

Chapter 3 — Programming I

Lesson map

Lesson 03 published. Map, example, EX007.

flowchart TD
  N0["Learning outcomes"]
  N1["3.1 Why program"]
  N2["3.2 Reading data carefully"]
  N3["3.3 Clear output"]
  N4["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4
  N4 --> EX["Worked example"]
  EX --> Q["Exercise EX007"]

Logical drawing

flowchart LR
  N0["Learning outcomes"]
  N1["3.1 Why program"]
  N2["3.2 Reading data carefully"]
  N3["3.3 Clear output"]
  N4["Synthesis"]
  N0 --> N1 --> N2 --> N3 --> N4 --> Q["EX007"]
[Learning outcomes]
    |
    v
[3.1 Why program]
    |
    v
[3.2 Reading data carefully]
    |
    v
[3.3 Clear output]
    |
    v
[Synthesis]
    |
    v
[Worked example] --> [Exercise EX007]

Learning outcomes

You will (1) write a simple script to count accounts; (2) read a CSV export; (3) print a clear summary.

3.1 Why program

Greenhill's office suite can export a list of accounts as a CSV file, a plain text table with one line per account. Counting by hand in a spreadsheet works once, but the check needs repeating every month. Elena writes a short Python script that reads the export, counts accounts by status and department and prints a summary. Using only the standard library means it runs on any Greenhill laptop without installing anything. Repeating the same script each month gives comparable results, which hand counting rarely does.

3.2 Reading data carefully

Real exports contain surprises: blank lines, names with commas, departments typed differently such as Housing and housing. Elena's script trims spaces, treats department names case-insensitively and reports any line it cannot read rather than silently skipping it. She tests the script on a small synthetic file where she knows the right answer before using the real export. If the script and her hand count disagree on the test file, she fixes the script, because a check that gives wrong answers is worse than no check at all.

3.3 Clear output

A good summary is easy to read and hard to misread. Elena prints a header with the export date, then a table of departments with total accounts, enabled accounts and accounts with multi-factor authentication, each as a count and a percentage of its base. She saves each month's output with its date so trends can be compared. The script is short, commented and stored in Greenhill's shared IT folder, so another member of the team can run it while Elena is away at university.

Worked example

Elena's script reads a synthetic export of 152 accounts, reports 140 enabled and 12 disabled, and lists departments with counts and percentages.

Synthetic case. Exports and counts are synthetic.

Errors and limits

A script that silently skips unreadable lines may undercount exactly the accounts that need attention.

Exercises

Synthesis

A small, tested script makes monthly account checks repeatable and comparable.

Continue studying — chapter 03 of 40

← Chapter 02 (draft) · Course chapter index · Chapter 04 (draft) →

Worked answers

EX007. A plain text table with one line per record.

EX008. By treating department names case-insensitively.

EX009. 140 enabled of 152 accounts.