Creating a Shakespearen Insult Generator – Part 1 (Python Tutorial)
- 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)
- 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
- 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:
In this lesson, students are going to create a Shakespearean Insult generator using lists in Python.
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:
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:
names = ["Bob", "Dave", "Stuart"]
Explain to students that lists start at 0 NOT 1.
e.g. if we were to run the following code:
The computer would return the name “Bob”
2. Ask the students to replace the last line with the following new code:
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:
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.
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.
2. Ask students to comment their code, using the hashtag (#), explaining what the code is doing
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/