Software Design Fall 2004 For next time: 1) finish Chapter 3 of "How to think..." 2) continue work on hw01 Linux review ------------ User and superuser Accounts and environments The prompt (typeahead) Files and directories The "working" directory pwd, ls and cd Absolute and relative paths Commands, arguments and options Syllabus -------- Administrivia for the whole family. Past projects (never too early...) Feedback on the surveys. Values and types ---------------- Everything is an object. Names refer to objects, so we draw them with arrows. x = 1 y = 1 What does the UML state diagram look like? All values have types. The expression 1 creates a reference to an integer object. 1.0 floating-point 1L arbitrary-precision integer! 'allen' string (double quotes work, too) Variables do not have types. Any name can refer to any type. x = 1 x = 1.0 x = 'allen' You don't have to declare variables, but you do have to avoid using keywords as variable names. Choosing good names is surprisingly important. Expressions ----------- Expressions are made up of operands and operators. The effect of the operator sometimes depends on the types of the operands. 1 + 1 integer addition 2.0 + 2.0 floating point addition 'a' + 'llen' string concatenation 'a' * 3 string multiplication? Gotchas 0) string operators: hoax or scam? 1) what if the operands don't match? 2) beware integer division 3) precedence: learn it, live it, forget it modulus ------- x % y is the remainder when x is divided by y (y is an integer) What is it good for? 1) 2) 3) 4) 5) for loops (an early bird special) --------- What do the following statements do? for c in 'allen': print c, for i in range(4): print i for statement is an example of a compound statement 1) header ending in : 2) indented body By convention, indentation is 4 spaces. End of body marked by an outdented line. bob = Turtle(world) for color in ['red', 'yellow', 'blue']: print color #inside the loop bob.set_color(color) #inside the loop bob.fd(100) #outside the loop Try it out! ----------- In Linux, create a console and type python. Python 2.2.2 (#1, Feb 24 2003, 19:13:11) [GCC 3.2.2 20030222 (Red Hat Linux 3.2.2-4)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> The chevron >>> is a prompt. You can type a python expression and the python interpreter will print the result. >>> 'allen' * 10 'allenallenallenallenallenallenallenallenallenallen' If you are not sure whether something is legal, try it! >>> 'allen' / 10 Traceback (most recent call last): File "", line 1, in ? TypeError: unsupported operand type(s) for /: 'str' and 'int' What does this error message mean to you?