In: Computer Science
THIS PROGRAM I HAVE MADE UP CHOOSES A RANDOM STORY AND IS IN MAD LIBS FORMAT.
IM HAVING A DIFICULT TIME FORMING A ALGORITHIM FOR THE PROGRAM. if you coukd develop a algorithim it will be greatly appreciated.
Thank you,
# Dillon
Montefusco, A, B
# need to write up a Mad Libs story itself.
# looping input where it prompts for a type of word
# need to write entire scripts (stories)
# use random to choose a story, so the user cannot read it and can enjoy with his friends also the story.
import random as r # for the story randomize agent
ri = r.randint
def okt(b): # octal number converter (ALL RIGHTS RESERVED, THIS FUNCTION IS OFF THE INTERNET)
n = int(b)
r = ''
while n > 0:
r = str(n % 8) + r
n //= 8
if r: return r
return '0'
def get_story(): # This is the story randomize agent
return ri(1, 0o3)
def word_prompt(pos): # part of speech
"""Function takes a word type (part of speech) and returns the word to be inserted in the mainString."""
word = input("Enter a "+str(pos)+": ")
if pos == 'name' or pos == 'male' or pos == 'female' or pos == 'city':
return word.title()
else:
return word.lower()
# THIS IS STORY 01 OF 20
def story01():
wp = word_prompt
story01 = "While going down the "+str(wp('name'))+" Bridge to "+str(wp('city'))+", something out-of-the-ordinary happened... \n\
a bunch of "+str(wp('plural noun'))+" were "+str(wp('verb'))+" over the traffic! It was pretty wierd,\n\
and definitely a "+str(wp('adjective'))+" sight to see, but I guess that's one way to beat the "+str(wp("adjective"))+" traffic. \n\
Man, I wish I could do the same."
return story01
def story02():
wp = word_prompt
story02 = "Homeboy "+str(wp('male'))+" pulled up to the "+str(wp('place'))+" and bought "+str(wp('number'))+" lottery tickets. \n\
Litte did he know, one of the tickets was a "+str(wp('adjective'))+" winner! \nOnce he checked the tickets, homeboy got so happy! \n\
Matter of fact, he was so happy that he "+str(wp('verb'))+" all the way home, \nbut dropped the winning ticket on the way. Long story short, he never got his money. \n\
Sucks to suck, doesn't it?"
return story02
def story03():
wp = word_prompt
story03 = "Back in the olden times there was a "+str(wp('mystical creature'))+" named "+str(wp('name'))+" that \
lived in a "+str(wp('adjective'))+" cave. \nIt was hella dusty in there, and the poor homie had \
trouble breathing. \nBut fear no more, because a "+str(wp('adjective'))+" wizard came through and pulled up with a \nmagical "+str(wp('item'))+" that \
cleaned up the place better than a swiffer sweeper duster! \nIf it wasn't for "+str(wp('male'))+" the Wizard, \
the "+str(wp('mystical creature'))+" would've gotten asthma. \nToo bad inhalers weren't invented back then."
return story03
# STORY DETERMINER
def story_determiner(count):
count = count
sn = get_story()
story_random = input("Get a random story?: ")
if story_random.lower() == "no":
story_prompt = input("Enter story number: ")
if story_prompt == "1" or story_prompt == "01":
input(story01())
repeat()
if story_prompt == "2" or story_prompt == "02":
input(story02())
repeat()
if story_prompt == "3" or story_prompt == "03":
input(story03())
repeat()
else:
input("Sorry, I can't recognise that story number!")
if count > 3: # hidden message counter
print("Have you really messed up", okt(count), "times!?")
story_determiner(count + 1)
elif story_random.lower() == "yes":
if sn == 1:
input(story01())
repeat()
elif sn == 2:
input(story02())
repeat()
elif sn == 3:
input(story03())
else:
input("Sorry, feature not available in the educational version!")
exit()
# OVERALL PROGRAM LOOP
def repeat():
a = input("Would you like to do another?: ")
if a.lower() == 'yes':
story_determiner(0)
elif a.lower() == 'no':
input("Thanks for playing! Press enter to close.")
else:
print("Bruh, how about you answer the question, eh?")
repeat()
story_determiner(0) # This line begins the program execution
# do comment if any problem arises
# Code
# Dillon Montefusco, A, B
# need to write up a Mad Libs story itself.
# looping input where it prompts for a type of word
# need to write entire scripts (stories)
# use random to choose a story, so the user cannot read it and can enjoy with his friends also the story.
import random as r # for the story randomize agent
ri = r.randint
def okt(b): # octal number converter (ALL RIGHTS RESERVED, THIS FUNCTION IS OFF THE INTERNET)
n = int(b)
r = ''
while n > 0:
r = str(n % 8) + r
n //= 8
if r:
return r
return '0'
def get_story(): # This is the story randomize agent
return ri(1, 3)
def word_prompt(pos): # part of speech
"""Function takes a word type (part of speech) and returns the word to be inserted in the mainString."""
word = input("Enter a "+str(pos)+": ")
if pos == 'name' or pos == 'male' or pos == 'female' or pos == 'city':
return word.title()
else:
return word.lower()
# THIS IS STORY 01 OF 20
def story01():
wp = word_prompt
story01 = "While going down the "+str(wp('name'))+" Bridge to "+str(wp('city')) + ", something out-of-the-ordinary happened... \n\
a bunch of "+str(wp('plural noun'))+" were "+str(wp('verb'))+" over the traffic! It was pretty wierd, \n\
and definitely a "+str(wp('adjective'))+" sight to see, but I guess that's one way to beat the "+str(wp("adjective"))+" traffic. \n\
Man, I wish I could do the same."
return story01
def story02():
wp = word_prompt
story02 = "Homeboy "+str(wp('male'))+" pulled up to the "+str(wp('place'))+" and bought "+str(wp('number')) + " lottery tickets. \n\
Litte did he know, one of the tickets was a "+str(wp('adjective'))+" winner! \nOnce he checked the tickets, homeboy got so happy! \n\
Matter of fact, he was so happy that he "+str(wp('verb'))+" all the way home, \nbut dropped the winning ticket on the way. Long story short, he never got his money. \n\
Sucks to suck, doesn't it?"
return story02
def story03():
wp = word_prompt
story03 = "Back in the olden times there was a "+str(wp('mystical creature'))+" named "+str(wp('name')) + " that \
lived in a "+str(wp('adjective'))+" cave. \nIt was hella dusty in there, and the poor homie had \
trouble breathing. \nBut fear no more, because a "+str(wp('adjective'))+" wizard came through and pulled up with a \nmagical "+str(wp('item'))+" that \
cleaned up the place better than a swiffer sweeper duster! \nIf it wasn't for "+str(wp('male'))+" the Wizard, \
the "+str(wp('mystical creature'))+" would've gotten asthma. \nToo bad inhalers weren't invented back then."
return story03
# STORY DETERMINER
def story_determiner(count):
count = count
sn = get_story()
story_random = input("Get a random story?: ")
if story_random.lower() == "no":
story_prompt = input("Enter story number: ")
if story_prompt == "1" or story_prompt == "01":
input(story01())
repeat()
if story_prompt == "2" or story_prompt == "02":
input(story02())
repeat()
if story_prompt == "3" or story_prompt == "03":
input(story03())
repeat()
else:
input("Sorry, I can't recognise that story number!")
if count > 3: # hidden message counter
print("Have you really messed up", okt(count), "times!?")
story_determiner(count + 1)
elif story_random.lower() == "yes":
if sn == 1:
input(story01())
repeat()
elif sn == 2:
input(story02())
repeat()
elif sn == 3:
input(story03())
else:
input("Sorry, feature not available in the educational version!")
exit()
# OVERALL PROGRAM LOOP
def repeat():
a = input("Would you like to do another?: ")
if a.lower() == 'yes':
story_determiner(0)
elif a.lower() == 'no':
input("Thanks for playing! Press enter to close.")
else:
print("Bruh, how about you answer the question, eh?")
repeat()
story_determiner(0) # This line begins the program execution
repeat()
Screenshot:
Sample run with random values: