Tip: Choose Save as PDF in the print dialog to download. Use A4 paper size.
Shade in the A or B circle for each question.
Draw a line connecting each item on the left to its match on the right.
| Left column | Right column | |
|---|---|---|
| 1chr((ord(ch) - 65 + shift) % 26 + 65) | Aresult += chr((ord(ch) - 65 + shift) % 26 + 65) | |
| 2if ch.isalpha(): | BUses = instead of += so each letter replaces the result and only the last letter is kept | |
| 3Build up the ciphertext one character at a time by adding each new character to a result string | CLeaves out % 26 so letters near the end of the alphabet do not wrap back to A and become symbols | |
| 4Wrap the loop in a function so you can encrypt any text with any shift | Ddef caesar(text, shift): | |
| 5result = chr((ord(ch) - 65 + shift) % 26 + 65) | EOnly shifts the character if it is a letter, so spaces and punctuation can be left unchanged | |
| 6chr((ord(ch) - 65 + shift) + 65) | FShifts the upper-case letter ch forward by shift places and wraps from Z back to A |
Complete each line of code by filling in the missing parts.
Shade in the letter of the line that contains an error.
chr((ord(ch) - 65 + shift) % 26 + 65) — Shifts an upper-case letter ch along the alphabet by shift, wrapping past Z back to A. A for loop applies it to each letter and builds the ciphertext with +=, skipping spaces.new = chr((ord(ch) - 65 + shift) % 26 + 65)new = chr((ord(ch) - 65 + shift) % 26 + 65)for ch in text:
if ch.isalpha():
result += shifteddef caesar(text, shift):
result = ""
return resultresult = ""
for ch in text:
result += new