Code-Along: Story Script

Follow these instructions to turn your story from the warm-up activity into a Python script!

If needed, click here for the starter project.

Background: Starter Code

There are a couple lines of code that should already be in the main.py file:

import time

This command imports the time library. This will allow python to sleep - basically, to wait some number of seconds before running the next command.

# Story will go below

This line is a code comment - basically, a line of code that does nothing, but can provide context or insight to the person reading the code.

It's up to you to add the code for the story below!

New Code

Follow the steps below to fill out the script.

  1. Re-open the forked project from the warm-up activity
    • If needed, fork another project using the link above
  2. Open the story.txt file for editing
  3. Highlight the first line of the story, and copy it
  4. Open the main.py file for editing
  5. At the bottom of the file, add a new line
  6. There, add a print statement to print out the first line of the story
    print("Once upon a time...")
    
  7. Make a new line under that
  8. There, add a time.sleep statement to wait for 1 second
    time.sleep(1)
    

Repeat the steps above for each line of the story!

Final Code

By the end of the activity, the code in the main.py file should look something like this:

import time

# Story will go below
print("Once upon a time...")
time.sleep(1)
print("There was a magical python.")
time.sleep(1)
print("She cast a spell on everyone and made them dance.")
time.sleep(1)
print("Everyone had a pretty good time.")
time.sleep(1)
print("The end.")

results matching ""

    No results matching ""