Python Story Generator Project
Do you believe random sampling is the most complicated application of Python's random module? No, we may use the random module to produce random tales or anything else. We'll show you how to make a narrative generator using Python in this post.
Python-based story generator
Every time the user runs the software, we must produce a random tale. We'll first store the portions of the tales in distinct lists, and then use the Random module to choose random sections of the stories from those lists:
To construct a random narrative, we first imported the random module, then built sections of the stories in separate lists, then randomly picked portions of the lists.
As a beginning, you are more interested in developing software applications, which is understandable. However, no matter what element of programming you are interested in, spending more time with programs that demand you to think rationally will always benefit you.
Source Code Python Story Generator
when = ['A few years ago', 'Yesterday', 'Last night', 'A long time ago','On 20th Jan']
who = ['a rabbit', 'an elephant', 'a mouse', 'a turtle','a cat']
name = ['Ali', 'Miriam','daniel', 'Hoouk', 'Starwalker']
residence = ['Barcelona','India', 'Germany', 'Venice', 'England']
went = ['cinema', 'university','seminar', 'school', 'laundry']
happened = ['made a lot of friends','Eats a burger', 'found a secret key', 'solved a mistery', 'wrote a book']
print(random.choice(when) + ', ' + random.choice(who) + ' that lived in ' + random.choice(residence) + ', went to the ' + random.choice(went) + ' and ' + random.choice(happened))
On 20th Jan, a rabbit that lived in Germany, went to the laundry and made a lot of friends
Although there are a few places where the above code may be improved, it passes several safe password creation criteria by today's standards on a basic level. As a beginner to Python or any other language, you should keep attempting these sorts of programs since they will help you learn more functions and, in the long run, will aid you in designing algorithms and doing well in coding interviews.
We hope you enjoyed this tutorial on writing a Python program to generate a random narrative generator.