1.4. WRITING A PYTHON PROGRAM 5
Python is used for software development at companies and organizations such as Google, Yahoo, Face-
book, CERN, Industrial Light and Magic, and NASA. Experienced programmers can accomplish great
things with Python, but Python’s beauty is that it is accessible to beginning programmers and allows them
to tackle interesting problems more quickly than many other, more complex languages that have a steeper
learning curve.
More information about Python, including links to download the latest version for Microsoft Windows,
Mac OS X, and Linux, can be found at http://www.python.org.
In late 2008, Python 3.0 was released. Commonly called Python 3, the current version of Python is
incompatible with earlier versions of the language. Currently the Python world still is in transition between
Python 2 and Python 3. Many existing published books cover Python 2, but more Python 3 resources now
are becoming widely available. The code in this book is based on Python 3.
This book does not attempt to cover all the facets of the Python programming language. Experienced
programmers should look elsewhere for books that cover Python in much more detail. The focus here is on
introducing programming techniques and developing good habits. To that end, our approach avoids some
of the more esoteric features of Python and concentrates on the programming basics that transfer directly to
other imperative programming languages such as Java, C#, and C
++
. We stick with the basics and explore
more advanced features of Python only when necessary to handle the problem at hand.
1.4 Writing a Python Program
The text that makes up a Python program has a particular structure. The syntax must be correct, or the
interpreter will generate error messages and not execute the program. This section introduces Python by
providing a simple example program.
A program consists of one or more statements. A statement is an instruction that the interpreter executes.
The following statement invokes the print function to display a message:
print("This is a simple Python program")
We can use the statement in a program. Listing 1.1 (simple.py) is one of the simplest Python programs that
does something:
Listing 1.1: simple.py
print("This is a simple Python program")
We will use Wingware’s WingIDE 101 to develop our Python programs. This integrated development
environment is freely available from http://wingware.com/downloads/wingide-101, and its target au-
dience is beginning Python programmers. Its feature set and ease of use make WingIDE 101 an ideal
platform for exploring programming in Python.
The way you launch WingIDE 101 depends on your operating system and how it was installed. Fig-
ure 1.1 shows a screenshot of WingIDE 101 running on a Windows 8.1 computer. The IDE consists of a
menu bar at the top, along with a tool bar directly underneath it, and several sub-panes within the window.
The large, unlabeled pane in the upper left portion of the window is the editor pane in which we type in
our program’s source code. The versions of WingIDE 101 for Apple Mac OS X and Linux are similar in
appearance.
To begin entering our program, we will choose the New item from the File menu (File→New menu
sequence), as shown in Figure 1.2. This action produces a new editor pane for a file named Unititled-1.py.
©2017 Richard L. Halterman Draft date: January 18, 2018