Creating a Shakespearen Insult Generator – Part 1 (Python Tutorial)
Learning Objectives:
- Understand and use sequence in an algorithm
- Understand and use iteration in an algorithm (FOR and WHILE loops)
- Understand and use selection in an algorithm (IF, Else and Else if)
- Understand and use data structures in an algorithm (for example, Lists, Tables or Arrays)
Curriculum Mapping:
KS2:
- Design, write and debug programs that accomplish specific goals; solve problems by breaking them into smaller parts. Select, use and combine a variety of software on a range of digital devices to design and create a range of programs.
- Use sequence, selection and repetition in programs; work with variables and various forms of input and output
- Use logical reasoning to explain how some simple algorithms work; detect and correct errors in algorithms and programs
KS3:
- Use two or more programming languages, at least one of which is textual, to solve a variety of computational problems.
- Make appropriate use of data structures [for example, lists, tables or arrays]; design and develop modular programs that use procedures or functions
How to make an Insult
To make an insult, pick one word from each of the columns (below), combine them to make a sentence and add the word “Thou” at the beginning. For example: If we were to take the first word from each of the 3 columns we would get:
Column 1 |
Column 2 |
Column 3 |
artless |
base-court |
apple-john |
In this lesson, students are going to create a Shakespearean Insult generator using lists in Python.
Starter:
Show students the online Shakespearean Insult generator (http://www.pangloss.com/seidel/Shaker/) or display a couple of random insults on the board as students enter the room e.g.
“Thou puny fly-bitten lout”
Before students create their Shakespearean insult generator, they need to become familiar with the random function in Python.
Tell students that they are going to write an algorithm to simulate the flipping of a coin.
Instruct students to type in and run the following code:
cointoss = random.randint(1,2)
if cointoss == 1:
print("Heads")
else:
print("Tails")
Extension:
Ask students to modify the code to simulate the rolling of a dice i.e. if the random function returns a 6, print the word “Six”.
Next, explain to students that they are going to create a random name picker and this will form the basis of their Shakespearean Insult generator.
1. Instruct students to type in and run the following code:
import random
names = ["Bob", "Dave", "Stuart"] print(names[random.randint(0,2)]) |
Explain to students that lists start at 0 NOT 1.
e.g. if we were to run the following code:
print(names[0])
The computer would return the name “Bob”
2. Ask the students to replace the last line with the following new code:
print(random.choice(names))
|
Ask students to run the new script and explain what the new code does.
3. Finally, inform students that we need to add (concatenate) the word “Minion” at the beginning of our randomly selected name.
Ask students to replace the last line with the following:
print(“Minion” + “ “ + random.choice(names))
|
Extension:
Ask students to add more names to the list.
Explain to students how the online Shakespearean Insult generator works (see introduction) and direct them to the Shakespearean Insult toolkit (http://www.pangloss.com/seidel/shake_rule.html)
Instruct students to, using what they have learnt and using the resources at their disposal, create their very own Shakespearean Insult generator. Tell students that they will need to use lists and that they will also need to use the random function.
Tip: If you prefer, you may wish to provide students with a template with the lists already created (see below) – this will save the students from having to type all the words. You can then ask the students to add a fourth list with alternate sentence starters e.g. “Thou”, “Thee”, “Ye Olde” etc.
shakespearean_insult_template.py |
insult_creator_v1.py |
Extension: Tkinter
Tkinter is the default GUI that is shipped with Python. With tkinter, it is easy to create GUIs to use with your Python code such as windows and buttons.
insult_creator_v2_tkinter.py |
2. Ask students to comment their code, using the hashtag (#), explaining what the code is doing
Alternative:
Alternatively, you could ask students to create a random compliments generator.
Next: Part 2 – File handling
Unless otherwise specified, everything in this repository is covered by the following licence:
Based on the Shakespearean Insulter: http://www.pangloss.com/seidel/Shaker/