6.1 - Story time

Write a program that will tell the beginning, middle and end of a story. Each story section should be it’s own procedure.

A parameter will be passed to each procedure that will customise the story.

  • Beginning – name
  • Middle – monster
  • End – location

Using the problem description and design, implement the program.

Example run

Once upon a time a brave warrior named Zack entered a dungeon.
In the dungeon they battled a Dragon.
After the battle they retired to the village of Roselake.
1 Display the start of the story. IN name
2 Display the middle of the story. IN monster
3 Display the end of the story. IN location

 

1.1 display “Once upon a time a brave warrior named” + name + “entered a dungeon.”

2.1 display “In the dungeon they battled a” + monster + “.”

3.1  display “After the battle they retired to the village of” + Roselake + “.”

 

 

# Main
beginning("Zack")
middle("Dragon")
end("Roselake")
def beginning(name):
    print("Once upon a time a brave warrior named", name, "entered a dungeon.")

def middle(monster):
    print("In the dungeon they battled a", monster + ".")

def end(location):
    print("After the battle they retired to the village of", location + ".")

# Main
beginning("Zack")
middle("Dragon")
end("Roselake")
def beginning(name):
    print("Once upon a time a brave warrior named", name, "entered a dungeon.")

def middle(monster):
    print("In the dungeon they battled a", monster + ".")

def end(location):
    print("After the battle they retired to the village of", location + ".")

# Main
beginning("Zack") # Call beginning and pass the parameter "Zack"
middle("Dragon") # Call middle and pass the parameter "Dragon"
end("Roselake") # Call end and pass the parameter "Roselake"