Monday 20 November 2023

Story Generator in Python

 Using Random Module You Can Generate a random story 


1
2
3
4
5
6
7
8
import random
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']
namee=['Ali','Mariam','Daniel','Houck','Starwalker']
residence=['Barcelona','India','Germany','London','England']
went=['cinema','university','seminar','school','laundary']
happened=['made a lot of friends','eats a burger','found a secret key','solved a mystery','wrote a book']
print(random.choice(when)+', '+random.choice(namee)+' that lived in '+ random.choice(residence)+', went to the '+random.choice(went)+' and '+random.choice(happened))



Output 1:

A long time ago, Mariam that lived in Germany, went to the cinema and eats a burger

Output 2: 

Last night, Ali that lived in Germany, went to the seminar and solved a mystery

No comments:

Post a Comment