OpenCyber Academy
Bachelor's · Chapter 3 · English
Course code: OCA-102Chapter 03: OCA-102-C003

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.

Permanent link

Public activity · 30d

—Participating browsers

—Page views

—Reading sessions

—Exercise opens

Counts reflect browsers that allowed analytics. A reading session requires 30 seconds on a visible page. Browsers are not people.

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

  • EX007 — CSV meaning. What is a CSV export?
    Show marking criteria
    Rubric: 3 = plain text table, one line per account;; 2 = text table;; 1 = database;; 0 = none.
  • EX008 — Department case issue. How does Elena handle Housing versus housing?
    Show marking criteria
    Rubric: 3 = compares department names case-insensitively;; 2 = case-insensitive;; 1 = ignores;; 0 = none.
  • EX009 — Enabled count. How many enabled accounts does the synthetic export show?
    Show marking criteria
    Rubric: 3 = 140 of 152;; 2 = 140;; 1 = 152;; 0 = none.

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) →

Practice the exercises

Open a prompt, write your response, then compare it with the worked answer. Five-choice practice appears where a reviewed question is available.

EX007

Opens in 30 days: — · browsers: —

Checking for a reviewed five-choice question…

EX008

Opens in 30 days: — · browsers: —

Checking for a reviewed five-choice question…

EX009

Opens in 30 days: — · browsers: —

Checking for a reviewed five-choice question…

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.