OpenCyber Academy
Rapid course · Lesson 9 · English
Course code: OCA-019Lesson 09: OCA-019-A009

Width 14 does not edit the address

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

Lesson map

Lesson 09. Map, example, EX055.

flowchart TD
  S["String from requested"] --> W["Format width 14"]
  W --> L["Spaces after the digits"]
  L --> V["Verdict after one more space"]

The width pads the column. ip_address already ran on the unpadded string.

Logical drawing

format field {t:14}
  192.0.2.5     is 9 characters
  192.0.2.130   is 11 characters
  198.51.100.7  is 12 characters
pad
  spaces, not digits

Learning outcomes

After this chapter, you should be able to:

  1. Say what {t:14} changes on the line.
  2. Count the characters in 192.0.2.130 before padding.
  3. Refuse a reading that treats the spaces as part of the address.

9.1 The format width is a column. The address object is already built.

Each pass prints f"{t:14} {verdict}". For a string, :14 means a width of at least 14, aligned to the left. 192.0.2.5 has 9 characters, so five spaces follow it inside the field. 192.0.2.10 has 10. 192.0.2.130 has 11. 198.51.100.7 has 12. A further space, the one written between the field and {verdict}, separates the column from the words.

Those spaces are not fed back into ip_address. The membership tests used the original string. Changing the 14 would move the verdict column. It would not move .130 into the network, and it would not take .10 out of the set.

Lesson table; scroll horizontally to read all columns →

String Characters before padding What the width adds
192.0.2.5 9 Spaces to reach 14
192.0.2.10 10 Spaces to reach 14
192.0.2.130 11 Spaces to reach 14
198.51.100.7 12 Spaces to reach 14

9.2 Worked example

Lesson table; scroll horizontally to read all columns →

Offered claim What the format did Decision
"The gaps line the verdicts up." Left pad to 14, then one space Keep
"The address grew extra zero digits." Only spaces were added Refuse
"A shorter field would have changed EXCLUDED." The word was chosen earlier Refuse

Synthetic case. Width 14 is presentation. The four verdicts were already chosen.

Errors and limits

Do not read a space in the column as a digit of the address.

Apply

  • EX055 — Column width. What does {t:14} change, and what does it leave alone?
    Show marking criteria
    Rubric: 3 = it pads each stored string out to 14 characters with spaces; the address tested by ip_address is unchanged; the verdict word is unchanged;; 2 = the spaces are padding and not a new address;; 1 = one fact;; 0 = none.
Worked answers

EX055. {t:14} pads the stored string with spaces out to 14 characters. ip_address already used the unpadded string. The verdict word is unchanged.