DO NOT CHANGE THE FOLLOWING CODE: |
|
import list_lib as ll |
|
# END SECTION OF CODE YOU'RE NOT CHANGING |
|
|
|
# In this problem you will implement a bank account system using |
|
# Object Oriented Programming. Fill in the missing peaces in this |
|
# file. |
|
|
|
class BankAccount: |
|
def __init__(self, name, transactions, balance): |
|
# This class has three attributes: name (String), transactions |
|
# (array of tuples (date (String), description (String), amount |
|
# (Double)), balance (Double). Instantiate them using self and |
|
# the inputs to this method. |
|
# |
|
# Assume the date is in "dd/mm/yyyy" format. |
|
|
|
# __init_code__ here |
|
|
|
# Define getters and setters for each of the attributes. |
|
|
|
# Getters and setters code here. |
|
|
|
# Define a method called depost that takes as input a date, |
|
# transation description, and a transation amount, then updates |
|
# the balance and the transactions array. |
|
|
|
def depost(date, description, amount): |
|
# Fill in body of function |
|
|
|
# Define a method called expense that takes as input a transation |
|
# name, a transation amount, and then updates the balance and |
|
# the transations array. |
|
|
|
def expense(date, description, amount): |
|
# Fill in body of function |
|
|
|
def main(): |
|
# Initialize a new BankAccount object using your name, and some |
|
# dummy values for the rest of attributes. |
|
|
|
# Create three different deposits. |
|
|
|
# Create three different expenses. |
|
|
|
# Output the balance. |
|
|
|
|
|
|
import copy import sys import random def cons(x, l): new_l = copy.copy(l) new_l.insert(0,x) return new_l def head (l): if l == []: print("Cannot call head on the empty list.", file=sys.stderr) sys.exit() x , *xs = l return x def tail (l): if l == []: return [] x, *xs = l return xs def append(l1,l2): return l1 + l2 def reverse(l): new_l = copy.copy(l) new_l.reverse() return new_l def repeat(x,n): if n < 0:="" print="" ("cannot="" call="" repeat="" with="" negative="" values.",="" file="sys.stderr)" sys.exit()="" return="" [x]="" *="" n="" def="" _take(n,acc,l):="" if="" n="=" 0:="" return="" acc="" elif="" n="">< 0:="" print="" ("cannot="" call="" take="" with="" negagive="" values.",="" file="sys.stderr)" sys.exit()="" x="head(l)" rest="tail(l)" return="" _take="" (n-1,cons(x,acc),rest)="" def="" take(n,l):="" if="" l="=" []:="" return="" []="" return="" reverse="" (_take(n,[],l))="" def="" drop(n,l):="" if="" n="=" 0:="" return="" l="" elif="" n="">< 0:="" print="" ("cannot="" call="" drop="" with="" negative="" values.",="" file="sys.stderr)" sys.exit()="" es="tail" (l)="" return="" drop="" (n-1,="" es)="" def="" _length(acc,="" l):="" if="" l="=" []:="" return="" acc="" return="" _length(1+acc,tail(l))="" def="" length(l):="" return="" _length(0,l)="" def="" _randint_list(n,="" acc,="" low,="" high):="" if="" n="=" 0:="" return="" acc="" x="random.randint(low,high)" return="" _randint_list="" (n="" -="" 1,="" cons(x,acc),="" low,="" high)="" def="" randint_list(n,="" low,="" high):="" if="" n="">< 0:="" print="" ("cannot="" call="" randint_list="" with="" negative="" values.",="" file="sys.stderr)" sys.exit()="" return="" _randint_list(n,[],="" low,="" high)="" def="" _randfloat_list(n,="" acc,="" low,="" high):="" if="" n="=" 0:="" return="" acc="" x="random.randint(low,high)" return="" _randfloat_list="" (n="" -="" 1,="" cons(x,acc),="" low,="" high="" )="" def="" randfloat_list(n,="" low,="" high):="" if="" n="">< 0: print ("cannot call randint_list with negative values.", file=sys.stderr) sys.exit() return _randfloat_list(n,[], low, high) def unique(l): if l == []: return [] e = head (l) es = tail (l) new_tail = [x for x in es if x != e] return cons(e, unique(new_tail)) def list_range(low, high): return list(range(low, high)) 0:="" print="" ("cannot="" call="" randint_list="" with="" negative="" values.",="" file="sys.stderr)" sys.exit()="" return="" _randfloat_list(n,[],="" low,="" high)="" def="" unique(l):="" if="" l="=" []:="" return="" []="" e="head" (l)="" es="tail" (l)="" new_tail="[x" for="" x="" in="" es="" if="" x="" !="e]" return="" cons(e,="" unique(new_tail))="" def="" list_range(low,="" high):="" return="" list(range(low,=""> 0: print ("cannot call randint_list with negative values.", file=sys.stderr) sys.exit() return _randfloat_list(n,[], low, high) def unique(l): if l == []: return [] e = head (l) es = tail (l) new_tail = [x for x in es if x != e] return cons(e, unique(new_tail)) def list_range(low, high): return list(range(low, high))>