Do you think the most complex use of the random module in Python is random sampling? No, we can also generate random stories or anything beyond that using the random module. In this article, I’ll walk you through how to create a story generator with Python.
Story Generator with Python
Our task is to generate a random story every time the user runs the program. I will first store the parts of the stories in different lists, then the Random module can be used to select the random parts of the story stored in different lists
Source code:
Output:
On 20th Jan, a rabbit that lived in Germany, went to the laundry and made a lot of friends.
On 20th Jan, a rabbit that lived in Germany, went to the laundry and made a lot of friends.
I first imported the random module and then I created parts of the stories in different lists, then I only selected the parts of the lists at random to generate a random story.