Lab02: Python Comand Line and Thonny


The goal for this lab is to gain experience editing, compiling and executing Python programs in the terminal and through the Thonny IDE. You may work on this lab individually or in a group of no more than three people.

Executing Python in the Terminal

Each of the steps below should be completed entirely inside the terminal: no GUI applications allowed. Refer to the Unix Tutorial for Beginners if you need to learn more about Unix commands.

  1. Create a cs149 folder on your desktop
    mkdir cs149
  2. Move into the cs149 directory:
    cd cs149
  3. Create a folder inside your home directory named lab02.
    mkdir lab02
  4. Move into the lab02 directory:
    cd lab02
  5. Copy the file by doing a Right-Click Save-As and saving it to your lab02 folder. 
  6. Run
    $ python3
  7. Congratulations! You've successfully executed your first Python program.

Editing Files in the Terminal

Normally, we will be using an Integrated Development Environment (IDE) to edit and compile Python programs. However, it can sometimes be convenient to edit a file directly in the terminal. There are many terminal-based editors. Today we'll try nano because it is easy to use for beginners.

  1. Open using nano:
    $ nano

    You should see something like the following:

    Nano Editor screenshot

    The two lines of text at the bottom show the set of actions available in the editor. The "^" symbol indicates the "Ctrl" key. For example, pressing Ctrl-O will "WriteOut" (save) any changes you have made to the file.

  2. Edit the file so that the welcome message says "It's REALLY fun." instead of "It's fun.". Save your changes and exit.
  3. Try executing your program again:
    $ python3
  4. You should see the following output
    Welcome to CS149!
    It's REALLY fun.

Thonny IDE


  • Use an IDE (Integrated Development Environment).

  • Edit, save, compile, and run a simple Python program.

  • Recognize and correct syntax errors in a Python program.

Key Terms

source file
the Python program as written by the programmer
syntax error
mistake in the source code that prevents compilation
logic error
mistake in the program that causes incorrect behavior
the process of running a program on a computer

Part 1: Thonny Editor

Thonny  is a text editor designed to simplify the process of editing, debugging and executing Python programs.

  1. Open Thonny and click "File –> Open" from the menu and select your file from above.

    thonny editor

  2. Press the Green play button on the toolbar to execute the Python file(this is the same
    thing as running the >>python in the terminal.

  3. >>> %Run
    Welcome to CS149!
    It's REALLY fun.
  4. Edit the file in Thonny to print another line that prints
    I have edited a file in Thonny. 
  5. Save your results by pressing the Floppy disk icon then run the program again by pressing the Green play button.

  6. You have just run and edited a program using Thonny.

Submission for Lab2


This activity is based on a lab developed by Nathan Sprague based on a lab originally developed by Chris Mayfield.


Back to Top