Monday, September 28, 2009

All Chapters, Source Code for Listings

Here are all the listings for the book: Listings.zip

Chapter 8 Data Files

Again, several have asked for easier access to the sample data files used. Here are links to download the dictionary of words we used in the cryptanalysis chapter along with a link to the text of War of the Worlds.


War of the Worlds




wordlist.txt

chapter 7 Sample Data

Several people have requested that we post the image and sample data from chapter 7 here.

Here is the worldmap.gif

worldmap.gif


And here is the sample earthquakes.txt file:


2.8 2006/10/19 02:02:10 62.391 -149.751 15.0 CENTRAL ALASKA
2.5 2006/10/19 00:31:15 20.119 -156.213 1.5 MAUI REGION, HAWAII
5.0 2006/10/18 21:15:51 4.823 -82.592 37.3 SOUTH OF PANAMA
2.6 2006/10/18 21:12:25 59.934 -147.904 30.0 GULF OF ALASKA
3.4 2006/10/18 20:59:21 36.540 -89.640 7.7 SOUTHEASTERN MISSOURI
2.7 2006/10/18 20:11:22 61.023 -151.418 60.0 SOUTHERN ALASKA
3.1 2006/10/18 16:40:15 20.282 -156.611 4.7 MAUI REGION, HAWAII
2.7 2006/10/18 14:12:19 59.808 -152.538 50.0 SOUTHERN ALASKA
2.8 2006/10/18 14:02:12 60.686 -151.871 90.0 KENAI PENINSULA, ALASKA
4.9 2006/10/18 12:10:01 1.758 127.488 127.0 HALMAHERA, INDONESIA
6.2 2006/10/18 10:45:36 -15.081 167.243 138.5 VANUATU
2.8 2006/10/18 10:45:17 32.162 -115.895 6.3 BAJA CALIFORNIA, MEXICO
3.3 2006/10/18 10:08:45 32.165 -115.891 7.3 BAJA CALIFORNIA, MEXICO
2.8 2006/10/18 08:22:27 32.263 -115.297 3.4 BAJA CALIFORNIA, MEXICO
3.7 2006/10/18 05:34:15 62.326 -151.224 85.9 CENTRAL ALASKA
4.6 2006/10/18 03:25:03 -21.538 -66.593 201.7 POTOSI, BOLIVIA
3.7 2006/10/18 02:32:26 57.560 -137.186 1.0 OFF THE COAST OF SOUTHEASTERN ALASKA
4.9 2006/10/18 02:01:27 1.355 97.157 25.8 NIAS REGION, INDONESIA
2.5 2006/10/18 00:18:42 19.801 -155.391 10.6 ISLAND OF HAWAII, HAWAII
3.1 2006/10/17 22:59:01 61.444 -150.523 60.0 SOUTHERN ALASKA
3.1 2006/10/17 22:59:00 61.445 -150.656 50.0 SOUTHERN ALASKA
2.5 2006/10/17 20:58:26 34.145 -116.973 11.1 SOUTHERN CALIFORNIA
4.9 2006/10/17 20:53:16 40.403 -125.989 10.0 OFF THE COAST OF NORTHERN CALIFORNIA
4.5 2006/10/17 19:47:45 -20.911 -68.525 97.5 POTOSI, BOLIVIA
4.9 2006/10/17 19:19:08 37.542 142.864 8.9 OFF THE EAST COAST OF HONSHU, JAPAN
2.7 2006/10/17 18:49:24 19.852 -155.946 41.4 ISLAND OF HAWAII, HAWAII
3.5 2006/10/17 16:57:34 19.987 -156.028 43.5 HAWAII REGION, HAWAII
3.2 2006/10/17 15:32:34 32.339 -115.119 6.0 BAJA CALIFORNIA, MEXICO
3.9 2006/10/17 15:26:46 20.029 -155.957 12.6 HAWAII REGION, HAWAII
2.7 2006/10/17 15:24:31 50.899 -178.524 1.0 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
4.9 2006/10/17 14:37:53 63.103 -150.591 100.8 CENTRAL ALASKA
2.6 2006/10/17 13:32:04 52.681 -166.483 15.0 FOX ISLANDS, ALEUTIAN ISLANDS, ALASKA
3.0 2006/10/17 13:02:32 51.100 -179.318 15.0 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
3.2 2006/10/17 10:59:58 19.895 -155.893 35.7 ISLAND OF HAWAII, HAWAII
2.5 2006/10/17 10:41:51 40.634 -123.335 27.6 NORTHERN CALIFORNIA
5.4 2006/10/17 08:58:26 -5.854 151.145 32.8 NEW BRITAIN REGION, PAPUA NEW GUINEA
2.8 2006/10/17 08:56:30 36.110 -80.213 5.0 VIRGINIA-NORTH CAROLINA BORDER REGION
5.1 2006/10/17 07:59:18 10.305 91.787 30.0 ANDAMAN ISLANDS, INDIA REGION
3.2 2006/10/17 06:53:53 18.218 -68.190 150.8 MONA PASSAGE, DOMINICAN REPUBLIC
3.2 2006/10/17 06:20:33 20.090 -156.158 11.6 MAUI REGION, HAWAII
2.8 2006/10/17 05:18:04 35.230 -92.290 3.8 ARKANSAS
5.2 2006/10/17 04:30:51 45.226 150.022 47.0 KURIL ISLANDS
5.1 2006/10/17 04:20:18 -5.891 151.014 27.7 NEW BRITAIN REGION, PAPUA NEW GUINEA
5.7 2006/10/17 04:02:38 -20.995 -68.261 139.5 POTOSI, BOLIVIA
3.5 2006/10/17 02:27:48 18.915 -64.058 70.6 VIRGIN ISLANDS REGION
5.2 2006/10/17 01:59:14 -17.358 167.882 44.6 VANUATU
3.3 2006/10/17 01:31:52 18.996 -64.787 44.8 VIRGIN ISLANDS REGION
6.6 2006/10/17 01:25:13 -5.846 151.012 32.0 NEW BRITAIN REGION, PAPUA NEW GUINEA
2.9 2006/10/17 00:39:45 34.317 -118.456 5.0 GREATER LOS ANGELES AREA, CALIFORNIA
5.3 2006/10/16 23:23:19 48.226 153.160 139.2 KURIL ISLANDS
4.7 2006/10/16 23:03:58 -6.112 147.528 70.3 EASTERN NEW GUINEA REG, PAPUA NEW GUINEA
3.1 2006/10/16 22:34:38 59.634 -152.077 35.0 SOUTHERN ALASKA
2.9 2006/10/16 22:34:36 59.584 -152.074 20.0 SOUTHERN ALASKA
2.9 2006/10/16 20:15:55 46.172 -122.177 0.0 MOUNT ST. HELENS AREA, WASHINGTON
2.8 2006/10/16 19:03:52 19.890 -155.821 15.9 ISLAND OF HAWAII, HAWAII
4.8 2006/10/16 17:31:32 5.097 126.958 10.0 MINDANAO, PHILIPPINES
2.9 2006/10/16 14:10:54 58.812 -154.375 140.0 ALASKA PENINSULA
4.1 2006/10/16 14:10:04 33.837 70.296 80.3 PAKISTAN
2.5 2006/10/16 13:30:27 19.462 -154.897 3.1 HAWAII REGION, HAWAII
2.5 2006/10/16 11:59:39 19.771 -155.419 27.8 ISLAND OF HAWAII, HAWAII
4.7 2006/10/16 11:36:42 49.785 155.539 86.0 KURIL ISLANDS
3.7 2006/10/16 11:15:58 20.800 -156.939 7.2 MAUI REGION, HAWAII
2.5 2006/10/16 10:14:16 19.969 -156.029 16.7 HAWAII REGION, HAWAII
4.6 2006/10/16 10:11:07 1.183 -77.682 122.4 COLOMBIA
2.7 2006/10/16 08:46:23 20.105 -155.823 8.8 HAWAII REGION, HAWAII
2.7 2006/10/16 06:45:27 19.940 -156.053 9.6 HAWAII REGION, HAWAII
2.6 2006/10/16 05:40:57 32.341 -115.110 6.0 BAJA CALIFORNIA, MEXICO
2.5 2006/10/16 04:39:48 19.879 -156.058 13.2 HAWAII REGION, HAWAII
2.8 2006/10/16 04:22:35 19.922 -155.929 13.4 ISLAND OF HAWAII, HAWAII
2.5 2006/10/16 03:38:15 20.054 -155.983 10.0 HAWAII REGION, HAWAII
4.6 2006/10/16 02:51:27 41.228 141.970 51.5 HOKKAIDO, JAPAN REGION
2.6 2006/10/16 02:26:26 19.883 -156.069 15.5 HAWAII REGION, HAWAII
5.3 2006/10/16 01:33:34 -30.303 -71.472 47.1 COQUIMBO, CHILE
3.4 2006/10/16 01:11:04 19.887 -155.935 36.3 ISLAND OF HAWAII, HAWAII
5.8 2006/10/16 00:35:45 -50.900 158.830 0.0 NORTH OF MACQUARIE ISLAND
3.2 2006/10/16 00:22:01 58.829 -152.319 25.0 KODIAK ISLAND REGION, ALASKA
2.9 2006/10/15 23:58:05 62.539 -151.548 100.0 CENTRAL ALASKA
5.0 2006/10/15 23:50:13 -30.313 -177.818 35.0 KERMADEC ISLANDS, NEW ZEALAND
4.3 2006/10/15 22:08:44 -2.069 101.074 87.8 SOUTHERN SUMATRA, INDONESIA
2.7 2006/10/15 21:45:39 20.014 -155.783 10.9 HAWAII REGION, HAWAII
2.7 2006/10/15 21:30:25 20.625 -156.681 7.0 MAUI REGION, HAWAII
2.5 2006/10/15 21:08:10 19.924 -155.989 12.0 ISLAND OF HAWAII, HAWAII
4.4 2006/10/15 20:35:21 20.130 -156.025 24.9 MAUI REGION, HAWAII
2.7 2006/10/15 20:20:27 20.834 -156.643 5.4 MAUI REGION, HAWAII
2.6 2006/10/15 20:11:14 19.910 -155.920 11.7 ISLAND OF HAWAII, HAWAII
3.2 2006/10/15 19:57:45 19.852 -155.871 16.3 ISLAND OF HAWAII, HAWAII
4.8 2006/10/15 19:44:42 3.124 128.156 132.8 NORTH OF HALMAHERA, INDONESIA
3.1 2006/10/15 19:29:54 20.612 -156.248 7.0 MAUI REGION, HAWAII
2.8 2006/10/15 19:19:52 20.175 -155.962 7.8 HAWAII REGION, HAWAII
2.6 2006/10/15 19:17:38 19.844 -155.987 40.8 ISLAND OF HAWAII, HAWAII
2.5 2006/10/15 18:45:06 20.744 -156.356 7.0 MAUI REGION, HAWAII
2.5 2006/10/15 18:39:39 19.873 -155.626 0.0 ISLAND OF HAWAII, HAWAII
2.7 2006/10/15 18:34:47 19.943 -156.079 15.3 HAWAII REGION, HAWAII
2.9 2006/10/15 18:23:05 19.934 -156.020 11.1 HAWAII REGION, HAWAII
3.7 2006/10/15 18:19:58 19.936 -155.924 35.2 ISLAND OF HAWAII, HAWAII
2.6 2006/10/15 18:14:53 19.770 -155.773 30.3 ISLAND OF HAWAII, HAWAII
2.6 2006/10/15 18:10:44 19.811 -155.997 42.8 ISLAND OF HAWAII, HAWAII
2.5 2006/10/15 18:04:31 19.950 -156.020 16.4 HAWAII REGION, HAWAII
2.5 2006/10/15 17:56:27 19.855 -155.895 9.6 ISLAND OF HAWAII, HAWAII
3.1 2006/10/15 17:53:39 19.884 -155.957 9.0 ISLAND OF HAWAII, HAWAII
2.9 2006/10/15 17:50:29 20.015 -155.946 2.8 HAWAII REGION, HAWAII
3.1 2006/10/15 17:45:43 20.879 -156.894 7.0 MAUI REGION, HAWAII
2.6 2006/10/15 17:38:35 19.938 -156.030 13.4 HAWAII REGION, HAWAII
2.5 2006/10/15 17:35:57 19.918 -155.953 16.9 ISLAND OF HAWAII, HAWAII
3.1 2006/10/15 17:33:52 19.846 -156.178 37.6 HAWAII REGION, HAWAII
3.3 2006/10/15 17:30:02 20.154 -155.844 13.0 HAWAII REGION, HAWAII
3.6 2006/10/15 17:29:05 19.883 -155.896 36.6 ISLAND OF HAWAII, HAWAII
2.8 2006/10/15 17:27:35 19.868 -155.834 9.4 ISLAND OF HAWAII, HAWAII
6.0 2006/10/15 17:14:12 20.129 -155.983 18.9 HAWAII REGION, HAWAII
6.7 2006/10/15 17:07:48 19.801 -156.053 29.0 HAWAII REGION, HAWAII
2.9 2006/10/15 14:37:24 32.283 -115.122 0.0 BAJA CALIFORNIA, MEXICO
4.4 2006/10/15 13:34:35 -5.856 145.649 69.3 EASTERN NEW GUINEA REG, PAPUA NEW GUINEA
3.0 2006/10/15 12:58:03 57.476 -155.668 50.0 ALASKA PENINSULA
3.3 2006/10/15 12:27:20 19.579 -65.363 13.2 PUERTO RICO REGION
4.3 2006/10/15 09:12:54 25.268 141.101 290.1 VOLCANO ISLANDS, JAPAN REGION
4.5 2006/10/15 08:51:37 3.067 93.185 32.3 OFF THE WEST COAST OF NORTHERN SUMATRA
4.8 2006/10/15 04:48:19 -9.374 -78.851 49.8 NEAR THE COAST OF NORTHERN PERU
4.4 2006/10/15 04:43:05 -20.656 -178.768 639.1 FIJI REGION
4.0 2006/10/15 04:15:03 -22.265 -68.980 86.2 ANTOFAGASTA, CHILE
3.4 2006/10/15 03:30:11 59.578 -152.870 100.0 SOUTHERN ALASKA
4.4 2006/10/15 03:21:43 -20.098 -177.831 533.7 FIJI REGION
2.7 2006/10/15 02:46:40 59.204 -153.149 90.0 SOUTHERN ALASKA
4.0 2006/10/15 02:20:14 53.960 -164.059 1.0 UNIMAK ISLAND REGION, ALASKA
4.7 2006/10/15 01:35:11 34.958 33.813 38.5 CYPRUS REGION
3.0 2006/10/14 21:42:36 18.553 -66.207 89.7 PUERTO RICO REGION
2.8 2006/10/14 20:03:16 38.824 -122.783 0.1 NORTHERN CALIFORNIA
3.1 2006/10/14 18:01:54 38.816 -122.790 4.5 NORTHERN CALIFORNIA
4.8 2006/10/14 17:55:16 7.553 -78.118 12.0 PANAMA
3.7 2006/10/14 16:54:36 18.273 -63.883 93.2 VIRGIN ISLANDS REGION
2.7 2006/10/14 15:30:48 46.850 -121.594 5.2 WASHINGTON
5.1 2006/10/14 15:18:39 -23.017 -68.191 108.2 ANTOFAGASTA, CHILE
2.6 2006/10/14 15:15:27 37.520 -118.824 6.6 CENTRAL CALIFORNIA
2.6 2006/10/14 14:10:02 46.848 -121.587 6.3 WASHINGTON
3.3 2006/10/14 11:13:01 51.626 -166.466 1.0 SOUTH OF THE ALEUTIAN ISLANDS
3.3 2006/10/14 10:59:22 18.922 -64.475 6.1 VIRGIN ISLANDS REGION
4.8 2006/10/14 09:09:32 -31.458 -71.642 38.6 OFFSHORE COQUIMBO, CHILE
4.3 2006/10/14 07:41:08 51.400 15.960 10.0 POLAND
3.0 2006/10/14 06:49:27 18.831 -64.980 39.7 VIRGIN ISLANDS REGION
4.2 2006/10/14 06:02:12 20.756 120.272 35.0 PHILIPPINE ISLANDS REGION
4.3 2006/10/14 04:50:02 -7.808 127.500 10.0 KEPULAUAN BARAT DAYA, INDONESIA
4.6 2006/10/14 04:02:15 5.987 124.644 390.0 MINDANAO, PHILIPPINES
2.8 2006/10/14 03:55:33 58.598 -155.419 140.0 ALASKA PENINSULA
4.2 2006/10/14 02:05:46 11.376 -87.629 43.8 NEAR THE COAST OF NICARAGUA
5.3 2006/10/13 21:37:58 34.816 140.165 23.6 NEAR THE EAST COAST OF HONSHU, JAPAN
4.6 2006/10/13 21:31:00 14.371 -92.508 52.6 OFFSHORE CHIAPAS, MEXICO
4.3 2006/10/13 17:40:00 13.600 92.623 30.0 ANDAMAN ISLANDS, INDIA REGION
4.6 2006/10/13 17:31:30 -7.895 109.153 126.2 JAVA, INDONESIA
5.1 2006/10/13 16:12:55 -31.390 -71.540 31.1 COQUIMBO, CHILE
2.5 2006/10/13 16:09:58 61.119 -149.870 15.0 SOUTHERN ALASKA
4.3 2006/10/13 15:41:17 60.590 165.931 10.0 NEAR THE EAST COAST OF KORYAKIA, RUSSIA
4.4 2006/10/13 15:33:49 -6.826 106.289 137.0 JAVA, INDONESIA
4.9 2006/10/13 14:45:53 -22.847 -176.926 119.5 SOUTH OF THE FIJI ISLANDS
2.7 2006/10/13 14:39:49 46.197 -122.188 0.0 MOUNT ST. HELENS AREA, WASHINGTON
3.7 2006/10/13 14:00:01 50.200 -179.000 40.0 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
6.3 2006/10/13 13:47:40 46.311 153.273 8.8 KURIL ISLANDS
5.1 2006/10/13 10:28:45 -18.021 -69.148 133.2 LA PAZ, BOLIVIA
2.5 2006/10/13 10:03:28 63.211 -144.896 1.0 CENTRAL ALASKA
2.9 2006/10/13 09:36:33 18.579 -64.940 6.9 VIRGIN ISLANDS REGION
2.7 2006/10/13 09:13:37 62.711 -143.669 1.0 CENTRAL ALASKA
4.1 2006/10/13 08:51:05 -21.268 -67.707 118.1 POTOSI, BOLIVIA
2.6 2006/10/13 08:47:39 63.149 -144.574 10.0 CENTRAL ALASKA
4.8 2006/10/13 08:36:47 2.364 126.752 82.9 MOLUCCA SEA
5.2 2006/10/13 05:21:00 46.560 152.999 10.0 KURIL ISLANDS
2.9 2006/10/13 05:18:06 45.274 -123.031 16.8 OREGON
4.2 2006/10/13 05:15:26 51.978 152.821 418.6 NORTHWEST OF THE KURIL ISLANDS
4.0 2006/10/13 04:12:59 13.897 144.598 153.3 GUAM REGION
4.2 2006/10/13 03:11:04 -14.482 167.028 250.0 VANUATU
2.6 2006/10/13 02:29:00 59.733 -153.436 123.8 SOUTHERN ALASKA
4.6 2006/10/13 01:56:21 -15.500 167.339 98.7 VANUATU
4.8 2006/10/13 01:51:23 20.744 119.976 10.0 PHILIPPINE ISLANDS REGION
2.9 2006/10/13 01:20:12 38.792 -122.727 0.6 NORTHERN CALIFORNIA
4.8 2006/10/13 01:18:51 37.399 142.777 31.8 OFF THE EAST COAST OF HONSHU, JAPAN
3.7 2006/10/13 01:04:56 57.211 -155.440 100.0 ALASKA PENINSULA
5.0 2006/10/13 00:41:46 42.838 79.853 10.0 EASTERN KAZAKHSTAN
4.9 2006/10/13 00:32:09 -5.278 102.547 20.4 SOUTHERN SUMATRA, INDONESIA
5.1 2006/10/13 00:08:38 -7.560 127.790 112.4 KEPULAUAN BARAT DAYA, INDONESIA
4.7 2006/10/13 00:07:23 -56.020 -121.491 10.0 SOUTHERN EAST PACIFIC RISE
3.3 2006/10/12 22:41:17 32.315 -115.159 0.0 BAJA CALIFORNIA, MEXICO
3.5 2006/10/12 19:36:35 53.543 -164.431 35.0 UNIMAK ISLAND REGION, ALASKA
6.4 2006/10/12 18:05:56 -31.256 -71.390 29.3 COQUIMBO, CHILE
4.7 2006/10/12 18:04:50 51.762 -176.839 65.1 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
5.3 2006/10/12 17:08:20 39.811 54.730 41.2 TURKMENISTAN
5.0 2006/10/12 16:27:31 50.892 -173.057 2.4 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
4.5 2006/10/12 15:46:35 -1.845 127.606 35.0 KEPULAUAN OBI, INDONESIA
4.1 2006/10/12 15:42:50 -26.315 27.530 10.0 SOUTH AFRICA
2.6 2006/10/12 15:23:07 62.931 -150.579 100.0 CENTRAL ALASKA
5.7 2006/10/12 14:46:31 24.095 122.628 47.3 TAIWAN REGION
3.1 2006/10/12 13:49:53 53.762 -163.963 1.0 UNIMAK ISLAND REGION, ALASKA
4.6 2006/10/12 13:31:04 34.437 26.528 38.2 CRETE, GREECE
2.5 2006/10/12 12:02:48 51.175 -176.607 5.0 ANDREANOF ISLANDS, ALEUTIAN IS., ALASKA
4.5 2006/10/12 11:57:01 -19.716 -176.048 163.8 FIJI REGION
4.4 2006/10/12 10:23:02 8.538 -103.435 10.0 NORTHERN EAST PACIFIC RISE
2.6 2006/10/12 09:26:51 18.647 -65.990 65.1 PUERTO RICO REGION
4.9 2006/10/12 05:51:14 -23.420 -175.986 38.7 TONGA REGION
4.9 2006/10/12 05:30:38 -23.575 -175.851 55.4 TONGA REGION
5.5 2006/10/12 05:30:35 4.994 95.037 30.0 NORTHERN SUMATRA, INDONESIA
4.8 2006/10/12 05:26:06 -23.436 -175.869 35.0 TONGA REGION
4.5 2006/10/12 04:51:09 8.170 -103.488 10.0 NORTHERN EAST PACIFIC RISE
4.2 2006/10/12 03:20:06 37.830 29.188 8.9 WESTERN TURKEY
4.5 2006/10/12 03:09:04 -7.227 129.391 37.1 KEPULAUAN BABAR, INDONESIA
4.7 2006/10/12 02:26:30 -23.495 -176.040 67.8 SOUTH OF THE FIJI ISLANDS

Friday, September 25, 2009

Chapter 5 Listing 5.4

Here is a corrected version of listing 5.4. See the notes in the other listings for an explanation of the new urllib and the use of decode on the end of the readline call.


import urllib.request

def countHead(url):
"""docstring for countHead"""
page = urllib.request.urlopen(url)
numHeadLines = 0
numBodyLines = 0

line = page.readline().decode('ascii')
while '' not in line:
numHeadLines = numHeadLines + 1
line = page.readline().decode('ascii')

while "" not in line:
line = page.readline().decode('ascii')

while line != "" and "" not in line:
numBodyLines = numBodyLines + 1
print(line[:-1])
line = page.readline().decode('ascii')

print("number of lines in header = ", numHeadLines)
print("number of lines in body = ", numBodyLines)

page.close()

countHead("http://knuth.luther.edu/python/test.html")

Thursday, September 24, 2009

Chapter 2 -- Page 56 -- Problems 2.13, 2.14

It is probably more correct to define the Fibonacci sequence as starting with 0 and 1 as the first two numbers. In problem 2.14, assume that N will be greater or equal to 3

Wednesday, September 23, 2009

Chapter 11 Listing 11.12

The loop in lines 20 through 27 re-uses the newfish variable rather than a more correctly named newbear. the function still works properly but the variable name is confusing. Here is a corrected version of lines 20 -- 27.


for i in rnage(numberOfBears):
newbear = Bear()
x = random.randrange(myworld.getMaxX())
y = random.randrange(myworld.getMaxY())
while not myworld.emptyLocation(x,y):
x = random.randrange(myworld.getMaxX())
y = random.randrange(myworld.getMaxY())
myworld.addThing(newbear,x,y)

Chapter 10 Listing 10.9

The print on line 20 is missing parenthesis around the argument. The line should read:


print(aplanet)

Chapter 10 Exercise 10.17

The __getslice__ method does not exist anymore. The same functionality can be implemented bye writing your own __getitem__ method.

Chapter 9 Exercise 9.34

The rule F ->

means that F can be replaced by nothing.

Chapter 9 Listing 9.7

when setposition is called to restore the turtle's position and heading to a previously stored location, the tail should be up. so Lines 16 and following should read:


elif cmd == ']':
pos,head = stateSaver.pop()
aTurtle.up()
aTurtle.setposition(pos)
aTurtle.setheading(head)
aTurtle.down()

Chapter 5 page 174

On Line 9 the sentence should read

Without this call to readline, line would have no value. The book incorrectly states that read would have no value.

Chapter 3 Session 3.4

The last expression of Session 3.4 should be name[len(name)-1] not name[len(name)]. name[len(name)] generates a range error because the length of the string is 1 past the end of the string.

Friday, September 18, 2009

Chapter 2 -- Page 81 -- Problems 2.2,2.3,2.4

The problems say to use a parameter called n. It probably makes more sense to use r or perhaps radius.

Chapter 2 -- Page 81 -- Problem 2.5

The equation given in this problem is missing constants. It should read:

16 arctan(1/5) - 4 arctan(1/239)

Monday, September 7, 2009

Hanging Turtles

If you are using idle, some of the initial interactive examples will appear to hang. That is, if the turtle window gets behind another window its impossible to bring it to the front, and/or the window does not get refreshed. This is due to some weird threading interactions between the IDLE GUI and the shell. The problems are frustrating when you run into them in the first chapter. However as you write programs longer than 4 or 5 lines that include the exitOnClick call, they disappear quickly. A couple of suggestions to avoid this initial frustration:

  • Run these first examples from the command line shell. e.g. just type python3.1

  • Run idle using -n command line option. Windows and OS X can also be configured to start idle with -n

  • Carefully setup your idle shell and the turtle window so they are side by side with no other windows to distract.