Code With Me! - random catchphrase generator in Python
If you’ve been wondering what I do all day at my computer, here’s a quick program I wrote yesterday. Everyone who knows me in “real life” is probably tired of hearing me say “cool beans” and this program generates a random catchphrase.
Here’s a step-by-step guide to generating your own cool beans catchphrases.
Open an iPython 2 notebook in Jupyter by clicking on the New tab on the top right, then selecting Python 2.
Copy and paste my base code from my Github.
Press Shift+Enter to run the code! It should output a string, a string of words surrounded by quotation marks. Mine outputs “outstanding peaches.”
Personalize your catchphrase generator!
Make a new catchphrase generator like this:
name_of_generator = catchphrase([”noun_1”, ”noun_2”],[”adjective_1”, ”adjective_2”])
add nouns and adjectives to an existing generator like this:
name_of_generator.add_noun(”noun_3”)
name_of_generator.add_adjective(”adjective_3”)
Generate a new catchphrase like this:
name_of_generator.get_catchphrase()
How it works:
The generator stores a list of nouns and adjectives. Each time you ask it to generate a new catchphrase, it creates two pseudorandom numbers and picks out those elements from the lists, then sticks the adjective in front of the noun and outputs the result.
Adding adjectives and nouns to the generator just adds them to the end of the respective list, and then it outputs a new catchphrase, possibly containing one of the new words.
I hope you enjoyed coding with me! Reblog and put in the tags what you got as your catchphrase! If you have any questions about how the code works, or ways you think I can improve it, send me a message or an ask!
If the links didn’t work for you, you can copy and paste them from here:









