Shakespearean Compliment Generator
Overview
In this tutorial, you will make a 'Shakespearean' style compliment generator.
How it works
The program works by taking the familiar Shakespearean sonnet ‘Shall I compare thee to a summer’s day?’ but replaces the last two words with a random adjective followed by a random noun.
In this tutorial, you will make a 'Shakespearean' style compliment generator.
How it works
The program works by taking the familiar Shakespearean sonnet ‘Shall I compare thee to a summer’s day?’ but replaces the last two words with a random adjective followed by a random noun.
Type in and run the following code in the code window below:
import random
coinFlip = ["Heads", "Tails"] print(random.choice(coinFlip)) |
Challenge 1
Modify your code to simulate the roll of a dice (or to pick a name at random - e.g., Harry Potter style sorting hat).
Next, enter and run the following code:
Modify your code to simulate the roll of a dice (or to pick a name at random - e.g., Harry Potter style sorting hat).
Next, enter and run the following code:
#Superhero name generator
import random firstname = ["Red", "Green", "Yellow"] surname = ["Claw", "Spider", "Dynamo"] print(random.choice(firstname) + " " + random.choice(surname)) |
Challenge 2
Using what you have learnt, create your very own ‘Shakespearean compliment generator’.
Feeling a little stuck? Check out the partially working example below.
Partially working example
Using what you have learnt, create your very own ‘Shakespearean compliment generator’.
Feeling a little stuck? Check out the partially working example below.
Partially working example
#Shakespearean Compliment Generator
import random adjective = #Create a list of adjectives to choose from noun = #Create a list of nouns to choose from print("Shall I compare thee to a ") #add code to select and print an adjective and noun at random to complete the sentence |
Extra Challenge
Having very long lists is not very efficient, plus it makes the code more difficult to debug.
Modify your solution so that it uses a file for each list of nouns and adjectives rather than a list.
Having very long lists is not very efficient, plus it makes the code more difficult to debug.
Modify your solution so that it uses a file for each list of nouns and adjectives rather than a list.
Sample solution:
compliment_generator.zip |