This is a simple Python Project that creates a story generator. We will randomly fill phrases in the sentence template and generate three stories at a time.
Sentence template is "Scene", "who1" + "action" + "who2".
First step, I want to create four lists.
Second step, in order to randomly select items from the list, I will use built in library random. random.choice()
Third step, I will print out the sentence.
Last, we need to generate 3 stories at a time. Calling the same print statement three more time only gives the same stories three more times, so I am going to use a while loop.
Here is the sample result I got.
import random
stories_times = 0
while stories_times < 3:
scene = random.choice(["In an abandoned amusement park", "At a human zoo of the aliens", "In a city on Mars", "In a dream",
"In a hospital fulled with zombies", " In the magical world of Happy Porter",
"In the desert of Planet X", "On the edge of a cliff", " In a magical kingdom"])
who1 = random.choice(["a talking rabbit that can't lie", "a goblin who wants to be human",
"a women who remembers her past life", "a bounty hunter who is also a serial killer",
"a time traveler who love eat zombies",
"a young witch who accidentally turn herself into a giant pig forever", "an alcoholic detective",
"an escaped criminal and a dangerous mental patient", "A snake demon"])
who2 = random.choice(["a cult leader", "an astronaut who lost his memory ", "a dog who wanted world domination",
"a young couple who ran into the path of a psychopath", "baby Yoda",
"a bored vampire", " a mad scientist ", "the last chinese emperor", "an evil princess"])
action = random.choice(["fall in love with", "fights against", "hunt for gold with",
"befriend", "revenge the death of", "robbed", " ate ", "forced to kill", "made clothe out of"])
print(scene + ", " + who1 + " " + action + " " + who2 + ".")
stories_times = stories_times + 1
else:
print("The end.")
Here are some final results.
I hope you liked it.
Top comments (2)
Nice but please post the code in text instead of images.
Great idea. I am going to fix this week:) Thank you so much.