Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
24 views

Installing Python + IDLE Intro

Uploaded by

murpkyle278
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Installing Python + IDLE Intro

Uploaded by

murpkyle278
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Introduction to IDLE (and Python)

We will be using IDLE, which is an application for writing and running Python programs.

How do I get Python and IDLE?


- You can download Python and IDLE onto your computer by following these steps:

(1) go to www.python.org
(2) hover the mouse over Downloads tab – a dialog box will appear with download options, see
below (the download on the right is for a macOS because that’s the computer I have – it should
automatically adjust to your operating system, Windows vs. Mac vs. Other platforms)

(3) click grey button labelled Python 3.XX (see pink arrow above)
(4) double click on the file that downloads in your computer and click through the screens (to set up
Python on your computer).
(5) Once installation is complete, find the folder that python was installed in. My downloads are all in
one folder – if you can’t figure out where that is you can search for the word IDLE on your computer
(IDLE is the environment we will be using to write programs).
(6) Open IDLE by double clicking it

- When you double click IDLE to open it, a window called the python Shell opens up.

IDLE is open – now what?

The Shell window shows the output of your programs, which are typically written in another window called
the Editor window (more on this in a sec). You can also write short programs in the Shell window – but any
code you type directly into this window should be less than a line long.

Try typing something simple into the Shell, like 4+5, and then hit return:
Python shows the sum of these two numbers – so it essentially acts like a calculator.

We will be writing our programs in a different window, called the Editor window. To open this window, go
to File menu and click on New File, i.e., File->New File (this is the convention we will use to indicate you
should click on a menu within another menu). When you do that, a new window opens, initially called
Untitled (this is written in its title bar).

Do the following:
- type in 9+7 into the Editor window
- Go to File->Save and save this as test
- Now run this code, by going to Run->Run Module (if you don’t see Run as a menu, it means you need
to click on the Editor window)
- Recall that the output of the program is always shown in the Shell window. This is what your should
look like:

Where is the output (i.e., why didn’t the program show the sum of 9+7)? In order for the output to be shown
from a program written in the Editor window, we have to use the print command. Let’s do that.
Go back to the test Editor window, and add a print command, so that it looks like this:

Now save it (File->Save), and run the code (click on the test.py window, then select Run->Run module).
The output of the program is always shown in the Shell window, which has 16 in it as the last line. Now go
ahead and close the editor window (File->Close). Note: if you accidentally close the IDLE Shell window, go
to Run->Open Shell.

Thus, there are two windows: the Shell, which shows the output of programs (if any) and the
Editor, which is used to write code.
How do tell which window is the Shell vs. the Editor? The shell has “Python 3 Shell” in the window
bar. The editor window has the name of the file you gave it (or Untitled if you haven’t yet saved it).

To recap, here are the key steps that we need to do to write, run, and examine output of our
code:
- write python code in the Editor window
- save the code (File->Save) - Python makes you save any files in the Editor window before you
can run that code. These files are saved to your computer and can be retrieved from there.
- run the code (Run->Run module)
- the output of the code (if any) is displayed in the script window

A few tips:
- the menu bar options change depending on which window is active, the shell vs. the editor -
this is important, because if you want to, for instance, run your program, you will may not see the
Run menu until you click on an editor window.
- you can have more than one Editor window open, so make sure you are running the currently active
one (you make a window active by clicking on it)
- A caution: do not COPY and PASTE code from word documents etc. into IDLE but rather type it in
from scratch. This is because on some computers, copying introduces a different quote character that
python does not recognize and an error is produced.
- As noted above, if you accidentally close the IDLE Shell window, go to Run->Open Shell.

There are many nice IDLE tutorials out there if you want more details and tons of documentation – here are
a few sources to check out later if you wish:
- https://docs.python.org/3/library/idle.html
- https://www2.cs.arizona.edu/people/mccann/usingidle

You might also like