COMPSCI 61A Lecture 4: 8/30/17 Lecture 4
zogo39484755 and 6 others unlocked
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents
Document Summary
How to compute the fibonacci numbers with while function: def fib(n): Pred, curr = 0, 1 k = 1 keeps track of the index. Pred, curr = curr, pred + curr k = k + 1. Lots of different functions, but some are easier to understand. People used to program w/ just statements. Functions , univ accepted as ways to arrange functions. Function"s domain is set of all inputs it might possibly take as arguments. Function"s range is set of outputs values it might possibly return. Pure functions behavior is relationship it creates between input and output. Return value is the nth fibonacci number. Don"t repeat yourself, implement process just once, execute it many times. Assert r > 0, makes sure input is of certain specifications". Instead of sum_naturals, sum_squares, sum_cubes sum_powers. >>> total, k = 0, 1 while k <= n: return total. Return a function that takes one argument k and return k+ n .