2008/12/12 John Machin <[email protected]>: > (2) sequential search can be very fast if the sequence is in > descending order of probability of occurence ... you might like to > consider reversing the order
I find it hard to imagine a bank with so many interest rate thresholds that the search of the table is likely to be a significant contribution to the run time! > (3) for a much longer table, binary search using a function from the > bisect module could be considered > (4) in practice, the "default" action would not be "return 0.0"; > perhaps something along these lines: > > if balance < -overdraft_limit: > raise Exception(...) That's more likely to be in the withdrawal routine (and is probably best not handled as an exception, because it's pretty much normal flow). If a bank provided a service such as the one implemented by this program, there'd be no need for it to know about overdraft limits because it's not making actual transactions. Why would they increase coupling unneccesarily? -- Tim Rowe -- http://mail.python.org/mailman/listinfo/python-list
