COMPSCI 61A Study Guide - Midterm Guide: Cheat Sheet, Mutation, Object-Oriented Programming

36 views10 pages
8 Jan 2019
School
Professor
zogo39484755 and 6 others unlocked
COMPSCI 61A Full Course Notes
22
COMPSCI 61A Full Course Notes
Verified Note
22 documents

Document Summary

If you are not sure of your answer you may wish to provide a brief explanation. All the work on this exam is my own. (please sign) 2: (12 points) mutation and non-local assignment. The berkeley banking commune only accepts berkeley bucks. Each valid buck has a unique serial number. The bank tracks these serial numbers to make sure that nobody is photocopying its bucks. (a) (4 pt) the higher-order function make deposit returns a single-argument function deposit that takes a. If all serial numbers ever deposited to that function are unique, deposit returns the number of bucks ever deposited. If a duplicate serial number is ever deposited, deposit will forever return the string "fraud". Do not include any additional return statements; one is provided for you. def make_deposit(): "fraud" fraud = false contents = [] def deposit(bucks): if fraud: return "fraud" return len(contents) return deposit.