Write Your First Python Program

This lab takes you through creating a Python file in the Lesson01 folder, adding a docstring and a line of code, then executing it in Cloud9 IDE. Once you have completed this lab you will be able to create programs of your own and execute them.

Step 1: Use the Command Line to Create a File

Click into the terminal on Cloud9 so that you can enter UNIX commands.

Select the Terminal

At the prompt enter the following commands:

cd Lesson01
touch hello_python.py

The cd command changes the working directory to the Lesson01 directory. The touch command creates an empty file called hello_python.py.

Step 2: Open the File in Cloud9 IDE

You should see your new file if you expand the Lesson01 folder in the navigation pane on the right. As shown in the screenshot below.

Open a File

Double-click the hello_python.py file and you the editor will open.

Step 3: Add a Docstring

A docstring is a Python string that describes the file. Docstrings start and end with a triple-quote. Every Python file that you turn in should have a docstring with a particular format. Copy and paste this docstring into your file and replace “Your Name Here” with your name.

"""
CIS-15 First Program 
Your Name Here
"""

Step 4: Add Code

Below the docstring add this line of code:

print('Hello Python World')

Don’t forget to save your file!

Step 5: Execute Your Program from the Command Line

Using the terminal you can execute your code with the following command:

python3.6 hello_python.py

If you have done everything correctly you should see output like the screenshot below.

Run in Terminal

Step 6: Execute Your Program with the Run Button

Cloud9 gives you an easier (but less flexible) way to execute your code. Just click the ‘Run’ button near the top of the window. Execute your code with the Run button and verify that it works. You should see a Run tab with your program’s output like the screenshot below.

Run Button

Turn In

Turn in a screenshot of your first Python program in Cloud9.