Question

Using the script story.py as an example and possible starting point, write a script that generates a story using multiple levels of function calls that mirror the structure of your story. Your script...

Using the script story.py as an example and possible starting point, write a script that generates a story using multiple levels of function calls that mirror the structure of your story.

Your script must have the following requirements:

  • At least two functions must have randomly determined elements.
  • Your script must accept some form of user input (e.g. name of the hero), which is then used throughout the story.
  • The function structure of your script must have at least four levels. The example script only has three levels. To add a fourth level, you will need to define at least one extra function and have its returned result used by one of the functions at the bottom level (e.g. create_intro).
  • The script must have at least three function calls at some level in your script. The example script already meets this requirement.
  • The content of your story must be original.
  • The output of your story should be grammatically correct and neatly formatted.

script story.py:

# Sample story for assignment 6
import random

def create_whole_story(hero_name):
intro = create_intro(hero_name)
conflict = create_conflict(hero_name)
resolution = create_resolution(hero_name)
return intro + conflict + resolution

def create_intro(hero):
return hero + " lived in a land not too far away.\n"

def create_conflict(hero):
demise = random.choice(["ring of fire", "tarry pit", "dark abyss"])
return "Alas! {} fell into a {}.\n".format(hero, demise)

def create_resolution(name):
fate = random.choice(["lives", "dies"])
if fate == "lives":
return "Fortunately, wandering shepards came by and saved {}.".format(name)
else:
return "Sadly, that was the last we saw of {}.".format(name)
  

hero = input("What is the hero's name? ")

print("Here's your story...")
print(create_whole_story(hero))

0 0
Add a comment Improve this question Transcribed image text
Answer #1

# Sample story for assignment 6
import random

def create_whole_story(hero_name):
intro = create_intro(hero_name)
conflict = create_conflict(hero_name)
resolution = create_resolution(hero_name)
return intro + conflict + resolution

def create_intro(hero):
return hero + " was the strongest of all Vikings. "+create_intro2()

def create_conflict(hero):
demise = random.choice(["ferocious dragon", "dragon hunter", "group of invaders"])
return "While flying with his dragon, {} was attacked by a {}.\n".format(hero, demise)

def create_resolution(name):
fate = random.choice(["lives", "dies"])
if fate == "lives":
return "Fortunately, wandering Vikings came by and supported {} in the fight.".format(name)
else:
return "Sadly, his dragon was lost in the fight.".format(name)

def create_intro2():
return "He had a dragon named Thunder.\n"

  

hero = input("What is the hero's name? ")

print("Here's your story...")
print(create_whole_story(hero))

4 def create_whole_story (hero_name): introcreate intro(hero name) conflict-create_conflict(hero_name) resolutioncreate_resol

Add a comment
Know the answer?
Add Answer to:
Using the script story.py as an example and possible starting point, write a script that generates a story using multiple levels of function calls that mirror the structure of your story. Your script...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In Python and in one file please. (Simple functions with an expressions) Create a function called...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filenam...

    In Python and in one file please. (Simple functions with an expressions) Create a function called load_inventory(filename). The filename argument in this case specifies the name of a file that contains all the inventory/product information for the store, including product names, descriptions, prices, and stock levels. This function should clear any information already in the product list (i.e., a fresh start) and then re-initialize the product list using the file specified by the filename argument. You can structure your file...

  • Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America”...

    Read “Instituionalizing our Demise: America vs Multiculturalism” by Roger Kimball on pg 268 and “Reinventing America” Call for a new national indentity” by Elizabeth Martinez on pg 275. Create a double entry notebook for each reading selection It should be atleast five observation and responses. wric 268 PART 2 essay pro. exactly how and why their authors disagree. Instead of with parties in conflict as mediators do, you will nt of view designed to appeal to both sides, mediatn posing...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT