Loading topic
if statements and loops, and follow a short program by hand. You should also know what a base case and a recursive case are, since the previous chapter covered them. This chapter shows what Python actually does when a function call6 min readif statements and for loops, and read Big-O notation. It also builds on the two previous chapters. From the first, you need the idea of a base case and a recursive case. From the second, you need the picture of the call stack as a6 min readfactorial from the previous chapter, and have seen proof by mathematical induction at least once, even informally. You do not need any formal logic. The goal is a practical habit: when you write a recursive function, you should8 min readfactorial from earlier chapters. You will learn why deep recursion fails, what Python does to prevent a crash, and how to choose between rai6 min readRecursionError once the stack grows past its limit, which is 1000 frames by default.6 min readfib from the previous chapter is the starting point. It recomputes 6 min readfor loops, tuple assignment, and Big-O notation. We use the definition F(0) = 0, F(1) = 1, and F(n) = F(n−1) + F(n−2) for n ≥ 2.6 min read// is integer division and % is remainder in Python, and can reason with Big-O notation. Here we cut the cost of computing x ** n from n multiplications 6 min readfast_power function from the previous chapter works for any non-negative integer exponent. This chapter extends it to negative exponents. The math needs one line of code. Most of the chapter covers what can go wrong around that line: division by zero, infinite recursion caused by Python's floo6 min read% (remainder) and // (integer division) operators and with Big-O notation. The goal here is to compute values like 3^200 mod 13, or 7^(6 min read