CSCA48H3 Study Guide - Midterm Guide: Fibonacci Number, Call Stack, Memory Address

84 views5 pages
16 Oct 2018
School
Course
Professor

Document Summary

Recall the fibonacci sequence (1, 1, 2, 3, 5, 8, ) and the recursive fibonacci function de ned in class. Return the nth fibonacci number. """ if n == 0 or n == 1: return 1 else: return fib(n - 1) + fib(n - 2) if __name__ == __main__: print fib(3) On the opposite page is a memory model diagram in the style we have used in lecture. The diagram represents the contents of memory just before fib(3) has been called. Draw the call stack at the point where the rst call to fib(0) appears on the call stack. You may indicate the referenced location in memory using a memory address (which you make up) or an arrow. Write a class called quartermachine which represents a change machine (which takes bills and dispenses quarters). If the value passed to the quartermachine class constructor is not a non-negative integer, a typeerror should be raised.