Creating a Shakespearen Insult Generator – Part 1 (Python Tutorial)
Insult generator 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)
EDUCATOR: COMPUTATIONAL THINKING COMPETENCIES:
COMPUTER SCIENCE EDUCATORS:
CSTA K–12 CS Standards:
AREA OF LEARNING AND EXPERIENCE: Science and Technology:
Computation is the foundation for our digital world.
Progression step 3
- I can use conditional statements to add control and decision-making to algorithms.
- I can identify repeating patterns and use loops to make my algorithms more concise.
- I can explain and debug algorithms.
Progression step 4
- I can decompose given problems and select appropriate constructs to express solutions in a variety of environments.
- I can select and use data structures that efficiently manage data in algorithms.
- I can plan and implement test strategies to identify errors in programs.
Progression step 5
- I can identify, define and decompose problems, choose appropriate constructs and express solutions in a variety of environments.
- I can use file-handling techniques to manipulate data in algorithms.
- I can test, evaluate and improve a solution in software.
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:
print(“Minion” + “ “ + random.choice(names))
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/