Think Python: How to Think Like a Computer Scientist
Checking Types What happens if we call factorial and give it 1.5 as an argument? >>> factorial(1.5) Run ...
Debugging Breaking a large program into smaller functions creates natural checkpoints for debugging. If a functi ...
debugging. ...
Glossary temporary variable: A variable used to store an intermediate value in a complex calculation. dead ...
Exercises Exercise 6-1. Draw a stack diagram for the following program. What does the program print? def b( ...
empty string, which is written '' and contains no letters? 2 . Write a function called is_palindrome that ...
...
Chapter 7. Iteration This chapter is about iteration, which is the ability to run a block of statements repe ...
Reassignment As you may have discovered, it is legal to make more than one assignment to the same variable. ...
Updating Variables A common kind of reassignment is an update, where the new value of the variable depends on ...
The while Statement Computers are often used to automate repetitive tasks. Repeating identical or similar t ...
The condition for this loop is n != 1, so the loop will continue until n is 1 , which makes th ...
break Sometimes you don’t know it’s time to end a loop until you get halfway through the body. In that ...
Square Roots Loops are often used in programs that compute numerical results by starting with an approx ...
while True: print(x) y = (x + a/x) / 2 if y == x: ...
Algorithms Newton’s method is an example of an algorithm: it is a mechanical process for solving a category of ...
Debugging As you start writing bigger programs, you might find yourself spending more time debugging. More ...
Glossary reassignment: Assigning a new value to a variable that already exists. update: An assignment where t ...
Exercises Exercise 7-1. Copy the loop from “Square Roots” and encapsulate it in a function called mysqrt t ...
estimate of π. It should use a while loop to compute terms of the summation until the last term is sma ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf