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.
- Re-open the forked project from the warm-up activity
- If needed, fork another project using the link above
- Open the story.txt file for editing
- Highlight the first line of the story, and copy it
- Open the main.py file for editing
- At the bottom of the file, add a new line
- There, add a
print
statement to print out the first line of the storyprint("Once upon a time...")
- Make a new line under that
- There, add a
time.sleep
statement to wait for1
secondtime.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.")