Think Python: How to Think Like a Computer Scientist
Stack Diagrams To keep track of which variables can be used where, it is sometimes useful to draw a ...
print(cat) NameError: name 'cat' is not defined This list of functions is called a traceback ...
Fruitful Functions and Void Functions Some of the functions we have used, such as the math functions, r ...
Why Functions? It may not be clear why it is worth the trouble to divide a program into functions. There are se ...
Debugging One of the most important skills you will acquire is debugging. Although it can be frustrating, deb ...
Glossary function: A named sequence of statements that performs some useful operation. Functions may or m ...
A special value returned by void functions. module: A file that contains a collection of related funct ...
Exercises Exercise 3-1. Write a function named right_justify that takes a string named s as a param ...
+ - - - - + - - - - + | | | | ...
...
Chapter 4. Case Study: Interface Design This chapter presents a case study that demonstrates a pro ...
The turtle Module To check whether you have the turtle module, open the Python interpreter and type: >>> i ...
bob.lt(90) bob.fd(100) When you run this program, you should see bob move east and then north, leaving two l ...
Simple Repetition Chances are you wrote something like this: bob.fd(100) bob.lt(90) bob.fd(100) bob.lt(90) bob.fd(100) ...
Exercises The following is a series of exercises using TurtleWorld. They are meant to be fun, but they ...
Encapsulation The first exercise asks you to put your square-drawing code into a function definition an ...
Generalization The next step is to add a length parameter to square. Here is a solution: def square(t, len ...
Interface Design The next step is to write circle, which takes a radius, r, as a parameter. Here is ...
Refactoring When I wrote circle, I was able to reuse polygon because a many-sided polygon is a good approx ...
that you have learned something. ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf