Using IDLE to Write and Run Programs

Reading and Writing Python Files

About IDLE

What are the two main ways that we can use IDLE? →

  1. Create or open existing Python files in a text-editor view (and view the output of your program through the interactive Python shell)
  2. Type and run commands line-by-line through the Python Shell

Again, You Can…

Lastly, if your program ever outputs anything, it should show up in the interactive Python Shell

Starting IDLE

Just like what we did in the previous slides, to open IDLE:

DEMO - opening IDLE

Starting IDLE Continued

When you first open IDLE, you should see a window titled "Python Shell"

Managing Files

All file management activities can be found in the File menu:

Shortcuts for creating, opening and running a file are ⌘-n, ⌘-o, and the F5 key respectively.

DEMO - new window, open and run module

(Again, Feel Free to Follow Along!)

A First Program

"Hello world!" is traditionally the first program you write when learning a new language. It simply outputs "Hello world" (yeah, that's all). Follow these steps:

print("Hello world!")

Modifying Your Program

Let's modify the program that we just wrote:

print("Hi again!")

Making Mistakes

Let's purposely make a mistake, then fix it

print("Hola"

Making More Mistakes

Let's make a run-time error:

print("Howdy" + 2)
DEMO - make a run-time error QUESTION - what line number did the error happen on? DEMO - find the line

Errors

Notice that we looked at two different types of errors:

A Quick Note on Syntax Highlighting

DEMO - function and for loop for syntax highlighting

The Output Window and Interactive Shell

The Interactive Shell

DEMO - hello world in interactive shell

Help!

Note that typing help in the interactive shell actually gives you help! Let's try it!

>>> help

You can use help on specific things… for example: →

>>> help(print)

Additionally, you can check out the Python docs by going to Help → Python Docs in the menu.

Let's Provide Some Structure to Our Programming Process