Hey amazing people, today let’s build a Random Story Generator using Python.

How Our Story Generator works

Our random story generator will use a few lists of phrases and every time we run our program, a sentence will be randomly formed by picking phrases from those lists. Again it’s a fun and easy project so let’s get into coding.

Let’s Code

For this project, as we are going to randomly pick phrases, we need a module that can make our job easy. Any guesses which module I mean?

The random module! random module comes pre-installed with python hence we don’t have to manually install it. Let’s import it into our project.

import random

Now it’s time to define our lists which will contain random phrases.

when = ['A long time ago', 'Yesterday', 'Before you were born', 'In future', 'Before Thanos arrived']
who = ['Shazam', 'Iron Man', 'Batman', 'Superman', 'Captain America']
went = ['Arkham Asylum', 'Gotham City', 'Stark Tower', 'Bat Cave', 'Avengers HQ']
what = ['to eat a lot of cakes', 'to fight for justice', 'to steal ice cream', 'to dance']

#python #python-programming #python-tutorials #projects

Beginner Python Projects: Build a Simple Random Story Generator
3.35 GEEK