New
New
Year 11
OCR

Dictionary challenge

I can create an encryption program using a dictionary with key-value pairs.

New
New
Year 11
OCR

Dictionary challenge

I can create an encryption program using a dictionary with key-value pairs.

These resources will be removed by end of Summer Term 2025.

Switch to our new teaching resources now - designed by teachers and leading subject experts, and tested in classrooms.

These resources were created for remote use during the pandemic and are not designed for classroom teaching.

Lesson details

Key learning points

  1. A cipher is a type of secret code, where you swap the letters around so that no one can read your message.
  2. A Caesar cipher is one of the oldest and most famous ciphers.
  3. A dictionary data structure can be used to create a Caesar cipher.
  4. A dictionary maps one thing to another.

Keywords

  • Encryption - the process of applying an algorithm to plaintext to produce ciphertext that cannot be understood (without decryption)

  • Key-value pair - when a key (the attribute identifier) is paired with the data

  • Cipher - an algorithm used to convert plaintext messages to ciphertext (encryption) or ciphertext to plaintext (decryption)

Common misconception

A dictionary is a static data structure meaning you cannot add or remove items, only change the values that are available.

A dictionary is a dynamic data structure, which means you can add or remove items in the data structure during program execution.


To help you plan your year 11 computer science lesson on: Dictionary challenge, download all teaching resources for free and adapt to suit your pupils' needs...

This lesson is based on the Caesar cipher encryption algorithm. The process is modelled in the slide deck, but it may be useful to spend some time exploring the method if pupils have not experienced the algorithm before.
Teacher tip

Equipment

All pupils require access to devices that can edit and run Python programs. Starter code files are available to copy or use directly via the Raspberry Pi Code Editor.

Licence

This content is © Oak National Academy Limited (2025), licensed on Open Government Licence version 3.0 except where otherwise stated. See Oak's terms & conditions (Collection 2).

Lesson video

Loading...

6 Questions

Q1.
What is a dictionary used for in Python?
sorting numbers
storing multiple values in order
Correct answer: storing key-value pairs
looping through data
Q2.
In a Python dictionary, each item is made up of a and a value.
Correct Answer: key
Q3.
Which of these is a valid Python dictionary?
["apple", "banana"]
Correct answer: `{"apple": "fruit", "carrot": "vegetable"}`
{"apple", "fruit"}
("apple": "fruit", "carrot": "vegetable")
Q4.
What will this code output?
12
my_dict = {"a": 1, "b": 2} print(my_dict["b"])
Code colour

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
1
Correct answer: 2
a
b
Q5.
Dictionary keys must be ...
Correct Answer: unique
Q6.
What will this code do?
12
my_dict = {"cat": "meow", "dog": "bark"} my_dict["dog"] = "woof"
Code colour

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
Add a new key,
Correct answer: Change the value of dog.
Remove dog.
Print dog.

6 Questions

Q1.
What type of data structure is used to store key-value pairs in Python?
list
tuple
Correct answer: dictionary
string
Q2.
Match the keyword to the definition.
Correct Answer:dictionary,a data structure that uses data pairings which are located with a key

a data structure that uses data pairings which are located with a key

Correct Answer:key,used to identify each attribute held in a dictionary

used to identify each attribute held in a dictionary

Correct Answer:key-value pair,when a key (the attribute identifier) is paired with the data

when a key (the attribute identifier) is paired with the data

Q3.
A Caesar cipher with key +2 will change A to ...
B
Correct answer: C
D
Z
Q4.
What will be the output of this code?
12
caesar = {"Y": "A", "Z": "B", "A": "C"} print(caesar["Z"])
Code colour

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
Correct Answer: B, b
Q5.
To add a new key-value pair to a dictionary, you can use the operator.
Correct Answer: =, equal
Q6.
What does this line return?
1
chr(66)
Code colour

When programmers write code, they use a special tool called an IDE (Integrated Development Environment). In an IDE, different colours are used to help programmers understand the code:


  • • Blue - numbers and boolean values
  • • Green - strings
  • • Purple - keywords
A
66
Correct answer: B
b