Skip to content

Aug 21: Introduction

Lesson Outline

Introduction

Mini-Lab

  • Demonstration of Thonny Python IDE
  • Walk-through of how to submit on Gradescope

Lab - Introduction to Python and Thonny

The goal for this lab is to gain experience editing and executing Python programs in the terminal and through the Thonny IDE. You may work on this lab individually or with your classmates. You will submit it to a tool called gradescope, which checks your code. You are already added to a course there. Each of you must submit your own file, individually, by the due date.

Starting files

Download the following file to your computer: welcome.py

Objectives

  • Use an IDE (Integrated Development Environment).
  • Edit, save, compile, and run a simple Python program.
  • Recognize and correct syntax errors in a Python program.
  • Execute a Python program using the terminal.

Key Terms

source file - the Python program as written by a programmer; also known as source code

execute - the process of running a program on a computer

Part 1: Thonny IDE

Thonny is a simple IDE (integrated development environment): a text editor combined with other programming tools designed to simplify the process of editing, debugging and executing Python programs.

  • Open Thonny and click "File –> Open" from the menu and select the welcome.py file you saved previously.

  • Press the Green play button on the Thonny toolbar to run/execute the Python file. This is the same thing as running python3 welcome.py in the terminal.

  • You will see this output in the shell area at the bottom of the thonny window:

>>> %Run welcome.py
Welcome to CS149!
It's fun.
  • Edit the file so that the welcome message says "It's REALLY fun." instead of "It's fun.". Save your changes using the floppy disk icon in the toolbar.

  • Try executing your program again using the green play (run/execute) button. You should see the following output in the shell/console area:

>>> %Run welcome.py
Welcome to CS149!
It's REALLY fun.
  • Edit the file in Thonny to add another line that prints:

    I have edited a file in Thonny.
    

  • Save your results, then run the program again, and check that the output is correct

  • You have just run and edited a Python program using Thonny.

Submission for Lab 1

Submit here into gradescope.

Part 2: Using Python in the terminal

No submission is required for Part 2.

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. Open a terminal window.

  2. Assure that you are in the Desktop folder (directory), and, if not, navigate there.

    pwd
    

  3. Create a cs149 folder on your desktop

    mkdir cs149
    

  4. Move into the cs149 folder:

    cd cs149
    

  5. Create a folder inside your cs149 directory named lab01.

    mkdir lab01
    

  6. Move into the lab01 directory:

    cd lab01
    

  7. Copy the starting file welcome.py by doing a right-mouse-click Save-As and saving it to your lab01 folder.

  8. Run welcome.py:

    $ python3 welcome.py
    

Congratulations! You've successfully executed a Python program.

Acknowledgments

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