PON: Coding basics | Part 1

PON 2021: Coding basics (Python) | Part 1 - Overview

simple math | variables | assignments | Python Command Line & Python Scripts

Slides:

Homework:

Homework is always optional but a great way of practicing what you have learned during the course.
If you have questions, send them via e-mail. I might either respond to you individually or address common questions at the beginning of next the session.

Downloads (right-click & save as):

There are several ways of executing a python script like homework.py. Here is one of them:

  1. Download the file homework.py from above and save it on your computer.
  2. Open Spyder and open the homework.py in it (File -> Open...)
    You can find Spyder by searching in your start menu (or the Mac equivalent) or by opening the Anaconda Navigator, go to "Home" and click the "Launch" button for Spyder.
  3. You execute the entire script by hitting the "Play" button ("Run file") in the Spyder-Toolbar. The output of your script appears in the "Console" windows (bottom left of the Spyder window) - which is also a fully interactive console.
    Or you can try the other buttons next to it. Especially "Run selection" may come in handy.
  4. All further instructions are included in the script file. Just work through it from top to bottom.

Alternatively to Spyder, you can just open and edit it in your favorite text editor (Notepad or similar, NOT Word). Then open an Anaconda Prompt (On Mac/Linux: Open a Terminal, then type "conda activate"), navigate to the directory with your script file. Type python homework.py and hit "Enter" to run the script.