Creating a Shakespearen Insult Generator – Part 1 (Python Tutorial)
How to make a Shakespearean insult
To make a Shakespearean 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 |
Before creating your Shakespearean insult generator, let's explore the random function in Python.
Let's start by writing a program to simulate the flipping of a coin.
Type in the following code in the code window (below):
cointoss = random.randint(1,2)
if cointoss == 1:
print("Heads")
else:
print("Tails")
Challenge:
Modify your code to simulate the rolling of a dice i.e. if the random function returns a 6, print the word “Six”.
STEP 1
Let's create a random name picker. This will form the basis of your Shakespearean Insult generator.
Type in and run the following code:
import random
names = ["Bob", "Dave", "Stuart"] print(names[random.randint(0,2)]) |
Comment your code, using the hashtag (#), explaining what the code is doing and why the random generator is returning a value between 0 and 2 rather than 1 and 3.
Did you know?
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”
STEP 2
Replace the last line with the following new code:
print(random.choice(names))
|
Run the new script and explain what the new code does.
STEP 3
Finally, we need to add (concatenate) the word “Minion” at the beginning of our randomly selected name.
Replace the last line with the following:
print(“Minion” + “ “ + random.choice(names))
|
Challenge:
Add some more names to the list.
You now have all the components you need to create your very own Shakespearean insult generator.
Challenge:
Using what have learnt and using all the resources at your disposal, create your very own Shakespearean Insult generator.
Tip: You will need to create three lists (one for each set of words). For example:
column1=["artless", "bawdy"]
column2=["base-court", "bat-fowling"]
column3=["apple-john", "baggage"]
Support: If you prefer, I have provided a template with the lists already created (see below) – this will save you from having to type all the words in each list.
shakespearean_insult_template.py |
insult_creator_v1.py |
Unless otherwise specified, everything in this repository is covered by the following licence:
Based on the Shakespearean Insulter: http://www.pangloss.com/seidel/Shaker/