Ask coding questions

← Back to all posts
How to use random word module?

I want to know how to run the random word module in python 3. When I tested it out on my repl, nothing happens! So I want to know an example repl using the random word module.

Answered by Roar123 [earned 5 cycles]
View Answer

Well there are two approaches, you can use a library with words or write words to a source and pick a word from there. The easiest and fastest solution would be to copy paste words into a text file, such that each line has one word. The you would read a random line from that text and select your answer.

Note you could just read the entire contents of the text file and pick a word from there, but linecache.getline() does this optimally.
Here's the link to the repl with the code I wrote above:
Also the words are from MIT


What is the exact module you are trying to use?


@SixBeeps The Random_Word module