COMPSCI 61A Lecture 4: 8/30/17 Lecture 4

19 views3 pages
zogo39484755 and 6 others unlocked
COMPSCI 61A Full Course Notes
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 .

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents