Introductory Programming Fall 2004 For next time: 1) Read Chapter 3 of "How to think..." 2) Start Homework 2 But don't spend more than two hours. Debugging --------- "The programmer, like the poet, works only slightly removed from pure thought-stuff. He builds castles in the air, from air, creating by exertion of the imagination. Few media of creation are so flexible, so easy to polish and rework, so readily capable of realizing grand conceptual structures. Yet the program construct, unlike the poet's words, is real in the sense that it moves and works, producing visible outputs separate from the construct itself. It prints results, draws pictures, produces sounds, moves arms. The magic of myth and legend has come true in our time. One types the correct incantation on a keyboard, and a display screen comes to life, showing things that never were nor could be. ... The computer resembles the magic of legend in this respect, too. If one character, one pause, of the incantation is not strictly in proper form, the magic doesn't work. Human beings are not accustomed to being perfect, and few areas of human activity demand it. "Adjusting to the requirement for perfection is, I think, the most difficult part of learning to program." - F. Brooks ("The Mythical Man Month") Theorem: You have to get it exactly right. Corollary #1: You have to read and understand the error message when you get it wrong (so you should make lots of mistakes!). Corollary #2: You have to develop an eye for detail. Corollary #3: Practice! Dewey: "knowing is a form of doing" Corollary #4: The more sense it makes, the easier it is to spot errors. Math functions -------------- 1) You have to import the math module. In the book, I use >>> import math >>> math.sin(math.pi) But it's probably easier to use >>> from math import * >>> sin(pi) Some non-obvious math functions: 1) raising a number to a power either x**y or pow(x,y) 2) raising e to a power exp(x) 3) logarithms log(x) is the natural log log10(x) is the log base 10 Vocabulary ---------- 1) function call 2) argument 3) return value Printer configuration: See Chapter 3 of the Olinux manual.