Welcome to the web page for Python Programming Fundamentals written by Kent D. Lee and published by Springer-Verlag. This book was written as an introductory undergraduate text for the Introduction to Programming (CS1) course. The text is oriented towards students who have not taken any other programming course previously. However, it can be used by students with some programming skills in another language. If you would like to begin learning Python programming on your own, you can begin by installing Python and Wing IDE 101 on your computer. Then buy my book and begin working through the many practice exercises and examples in the text. The links to the two Youtube videos below show you how you can install Python and Wing IDE 101 on your computer.
- Installing Python and Wing IDE 101 on Mac OS X
- Installing Python and Wing IDE 101 on a Windows computer
I hope you enjoy reading the text and learning to program a computer using Python! It's creative, fun, and the skills you will learn could provide you with access to a very fullfilling and rewarding career in Computer Science! Give it a try!
Errata and Suggestions
I hope both professors and students enjoy using the text! I hope to get constructive feedback from folks so if you find an error or have a suggestion don't hesitate to email me. My email is kentdlee at luther.edu. Please contact me via email if you have errata or suggestions and I will post them here.
Instructor Support Materials
If you are an instructor using or considering using the text to teach a course and would like lecture slides, solutions to exercises, and answers to review questions I would be happy to provide them. Detailed lecture slides are available with all examples and practice problems from the text as well as solutions to all the exercises and review questions from the text. Please email me and provide me with information about where you are teaching and a web site where I can verify that you are a teacher at your institution and I will email you a userid, password, and link where you can download the support materials.
Here is a sample lecture schedule for a 14 week semester.
- Website made available January of 2011.
Support Files for Individual Chapters
The following sections contain support files, instructional videos, and additional information for individual chapters. The support files may be downloaded by students or faculty to complete projects from each of the chapters below.
The sections below also contain videos for the various topics presented in the text. These videos help to reinforce the topics discussed in the text. I would recommend that you watch the video and then read the section of the text that goes along with the video for a more detailed explanation of the concepts in that section.
In addition, there are practice exercises in each section of the text (with answers at the end of the chapter) that you can use to test your understanding material. Use these exercises to motivate your reading of the text.
Chapter 1Click to expand or contract
The first chapter is about 30 pages long and contains a variety of learning objectives. This is perhaps the most broadly focused of the chapters in the text. Its goal is to give you some basis for talking about computer programming and to give you a gentle introduction to the process of writing programs. Specifically, the learning objectives of the first chapter are outlined below.
In this section of the text you use the Wing IDE to write a simple program. You learn the steps that you must take to open the Wing IDE, enter a program, and run it.
In this section you learn a little about the architecture of a computer and some general terms to use when talking about computer programs. This includes:
- CPU - Central Processing Unit
- RAM - Random Access Memory
- Hard Drive - A Persistent Storage Device
Section 1.5 & 1.7
In sections 1.5, 1.6, & 1.7 you learn a little about binary and how numbers and letters are represented in a computer. Topics in this section are:
- Binary - the language of computers
- Signed number representation in binary - Representing both negative and positive binary numbers
- An algorithm for converting from decimal to binary and a little about hexadecimal notation
Sections 1.5 - 1.8
In these sections of the text, you learn about the importance of types in our programs and ASCII representation of characters.
Use an assignment statement in Python to store a value in RAM and retrieve it later.
Section 1.9 and 1.17
In section 1.9 and 1.17 you learn what a syntax error is, how to recognize it in your program, and how to fix it.
In this part of the text you learn about references, types, and type conversion.
Sections 1.15 & 1.16
Here you practice with strings and getting input from the user and printing output.
Chapter 2Click to expand or contract
In chapter 2 you learn how to make decisions in your programs using if statements. An if statements alters the sequence of executed statements depending on a condition. You also learn about the guess and check pattern of computation. This pattern is important to learn and memorize because you use it over and over in programs you write. Learning objectives for this chapter are outlined below.
Sections 2.1 & 2.2
Here you learn about the guess and check pattern of computation. You can watch this video that goes along with these chapters.
Sections 2.3, 2.4, & 2.5
In these sections you learn about choosing from a list of alternatives, Boolean values, and short-circuit logic. The video below helps to further explain these concepts.
In this section we learn that floating point numbers are only approximations of real numbers and therefore we must take some care when comparing floats for equality. It is likely that two floats will be close to the same value, but not exactly the same value, even when we would like them to be equal. The video below helps to illustrate this problem and the solution to it.
Chapter 2 Exercises
In exercise 2 of chapter 3 the problem asks you to write a menu driven address book program. You can use this text file as the data file for your address book or you can create one yourself. Just be sure to use the same format as is presented in the book for your records within the file.
Chapter 3Click to expand or contract
In chapter 3 you learn how to repeatedly execute code in programs so you can process repetitive data. This is where computers really are important, since people don't like to do the same thing over and over again. Computers are good at doing the same thing over and over. Again, there are video lectures below that complement the text.
You should read the introduction to chapter 3 as well. In these two sections you learn about sequences and how to iterate over them.
In this section you learn about nested for loops. Nested for loops are when you have one loop inside another loop.
In this section of the text you learn how to use the guess and check pattern when a list is involved.
Sections 3.5 & 3.6
In these sections of the text you learn about the accumulator pattern and how to use it to count or add together a list of numbers.
Chapter 4Click to expand or contract
In chapter 4 you learn about objects and how to create objects and call methods on them. The chapter uses turtle graphics and XML parsing as two examples where many objects are created and methods are called. Videos below complement the material covered in the chapter.
Sections 4.1 - 4.3
The introduction and these sections of the text show you how to use modules in Python and how to create some objects. This video complements these sections of the text.
In this video you learn how to use turtle graphics to plot data that you read from a file. In this video I read the file called djia-100.txt. This file is provided here for you to download if you want to try out my example.
In this section of the text you learn about dictionaries in Python. It shows you how to create a dictionary, put a key/value pair in dictionary, and how to lookup a key in a dictionary to get its value. The video below demonstrates these concepts as well.
Sections 4.6 - 4.9
In these sections of the text you learn how to read and parse through the information in an XML file. XML documents are used in many different applications these days and understanding what an XML document is and how to read it in a program is a valuable skill. The video below helps to illustrate these ideas. This video use an XML file called kml.kml as an example. That file can be downloaded here if you want to try my example.
In this section of the text I show you how to get at the attributes in an XML element. The attributes are recorded as a dictionary so you'll want to know what a dictionary is first (see section 4.8 and its video above). In the video that goes along with this section I read a couple of XML files called biking3-15-2012.tcx and workouts.tcx. You can download these files here if you want to try my examples.
Chapter 4 Exercises
In chapter 4 there are several programming problems that must read data from a file. In a few cases, some code is provided to get you started. Each exercise's extra files are provided below.
- Exercise 1 from the end of chapter 4 requires you to read an XML file and plot workout data. The exercise is described in more detail here.
- Exercises 3 and 4 require you to read a file. You can write the program to read an XML formatted file containing workout data as described in chapter 4. However, your teacher may want you to start by reading a file with the workout data already extracted. The three files below contain just the trackpoint data of three different bicycle workouts. Each line of the file is one trackpoint (one data recording instance during the workout). Each line is in the format of timestamp, distance, cadence, and heart rate as comma separated values. Check with your instructor to see if you can use these files to complete your program.
- Exercises 5 and 6 use mileage and fuel data from a 2007 Toyota 4Runner, a 2007 Nissan Versa, and a 2007 Suzuki S40 motorcycle. These two programs require you to read one of these data files below. This data was exported from a program called Gas Cubby that is available as an iPhone/iPod Touch App.
Chapter 5Click to expand or contract
Chapter 6Click to expand or contract
Chapter 6 introduces Tkinter programming through an example Reminder application. Documentation for the Tkinter API can be found here. You can download the Reminder.py code from the example in that chapter here.
- Exercise 4 requires you to create an XML file to hold the reminder notes when the program is terminated and for the program to read when the application is started. You can use the format found below for your XML file. Name the file "Reminders.xml" and place the xml file in the same directory or folder as your program. You can begin this exercise by downloading the Reminder.py program from the link above and then modifying the code to read from an XML file using the minidom parser described in chapter 4. You can write to a file using Python's file write method like the code in Reminder.py already does. Of course, you need to modify the code to write the file in this XML format so it can be read by the minidom parser.
One thing to be aware of: When using double quotes (i.e. ") in strings, you can you single quotes (i.e. ') to delimit those strings. Python lets you use either double or single quotes to delimit strings and this is one instance where using single quotes will come in handy.
One other thing to be aware of: Sometimes exception handling code (i.e. try except statements) get in the way of debugging your code. You may want to remove (or just comment out) the try except statements in the Reminders.py program before making modifications to it so you can see what errors occur when you make the modifications for this assignment. You should put the try except statements back in once you have debugged your code.
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<Reminders x="121" y="76">
<Note x="205" y="374">
Take out garbage.
<Note x="132" y="602">
Pick up mower blades.
Chapter 7Click to expand or contract
In chapter 7 there are two sample programs that are developed to demonstrate object-oriented programming and inheritance using Turtle graphics. The first is a drawing program. The source code for the drawing program can be downloaded here. The second example is a bouncing ball program and that code can be downloaded here. The bouncing ball program needs the soccerball.gif file to run. You might also like to make kitties bounce around, so kitty.gif is also provided. The GravityBall class from the text is given here for quick reference. There are a couple of changes from the GravityBall that appears in the text. The
Chapter 7 includes an exercise on developing an asteroids application. There are several web pages that will take you through developing this application. The four lessons below can be followed to implement the basic asteroids application. As part of the assignment, you are to implement one more level to the application when level 1 is completed.
In addition to the exercises at the end of chapter 7 I have had students implement a minesweeper game. This web page provides a sample as a compiled Python program and provides students with directions for completing the application from the starter code that is provided to them.