Readings: [1.3]: Creating a Program With IDLE

Introduction

This lesson is about creating a Python program. A program is a series of coding statements saved in a file. Rather than entering individual statements into an interactive shell such as that provided by IDLE, the objective is to enter statements into a file and execute them as a unit.

Creating a Python File

In IDLE, select File/New from the menu, or use the shortcut combination CTRL-N. Both will open a new, blank IDLE editor window.

The default IDLE window is empty. This displays a command prompt (>>>) to enter commands.

IDLE Window has Command Prompt

IDLE Window has Command Prompt

The IDLE File menu allows you to create a new file or open an existing file. For a new file, the editor is empty.

IDLE Blank Editor

Create New File in IDLE

Enter your program in the editor window. It is okay to enter a few lines at a time before testing it.

Enter Code in IDLE Editor

Enter Code in IDLE Editor

Save the file using the File menu or CTRL-S.

Save the Python Program as a File

Save the Python Program as a File

To run the program, using the menu or CTRL-F5.

Run the Python Program

Run the Python Program

The program will execute or run in the main IDLE window. Do not confuse this with your program in the editor.

Test the program to see that it runs as expected. Most assignments will provide details on how to test the program (how the Instructor will test it for grading). If that information is available, make sure your program produces the same results as the testing guidelines. Test multiple times!

Figure 6: Test the Python Program

If you make changes to the program, re-save it (using the menu or CTRL-F5) before running it again.

Always run the program to test it before submitting the file for an assignment. The editor saves the program with a .py extension. Submit the .py file for the assignment. (Do not copy/paste IDLE window code or results)


Keywords Covered in this Article