Python Project 1: Story Program

Setup

1. Go to the https://repl.it website and click on the Start coding button on the top-right of the screen.

2. Search for the language Python and then click Create repl

3. The center column (labelled main.py) is the code window, and the right column is the terminal, where you can see your program running.


Challenge 1: Outputting text

Output in Python

When writing Python code, you can write text to the screen using the print function. After the print keyword, you must have open and closing parentheses, and then you put your text within two double-quotes. For example:


Python codeExample output
print( "Hello!" ) Hello!
print( "How are you?" )
print( "I am good!" )
How are you?
I am good!

Challenge: Use this information to write a program that displays a story to the screen. Your story can be about anything. Here is my story:


Challenge 2: Getting user input

Input in Python

When writing Python code, you can ask the user to enter some information using the input function, and store their answer in a variable.

A variable is how we store information in a program, whether it's a number or text or sounds or images. You can name your variable anything - with a few restrictions. In general...


Python codeExample output
name = input( "What is your name?" ) What is your name? _
food = input( "Enter the name of a food:" )
print( "I like", food )
Enter the name of a food: BURRITO
I like BURRITO

You can insert the text stored in the food variable by using a comma between the double-quotes and the variable name.

Challenge: Update your story so that the user has to type in a few items before the story, such as the character's name, or an object in the story. Then, replace that text in your story with the text entered by the user.

Debugging your code: If Python detects an error (when you try to run your program), it will display an error message. Sometimes, it can take practice to figure out what is going wrong with your program, because the error messages aren't always helpful!

If you're getting an error, feel free to ask for help!

Here are a few errors you might run into: