Strict Standards: Declaration of Doku_Renderer_metadata::table_open() should be compatible with Doku_Renderer::table_open($maxcols = NULL, $numrows = NULL, $pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 24

Strict Standards: Declaration of Doku_Renderer_metadata::table_close() should be compatible with Doku_Renderer::table_close($pos = NULL) in /home2/cp-wiki/htdocs/inc/parser/metadata.php on line 24

Warning: Cannot modify header information - headers already sent by (output started at /home2/cp-wiki/htdocs/inc/parser/metadata.php:24) in /home2/cp-wiki/htdocs/inc/actions.php on line 581

Warning: Cannot modify header information - headers already sent by (output started at /home2/cp-wiki/htdocs/inc/parser/metadata.php:24) in /home2/cp-wiki/htdocs/inc/actions.php on line 581
cs190c:lab7
Table of Contents

Lab 7: First Hour

Sample Solution

from numpy import round, floor
from random import uniform
 
def create_accounts(n):
   accounts = []
   for i in xrange(n):
       accounts.append(round(uniform(0.01, 10000.0), 2))
   return accounts
 
def real_interest(accounts, p):
   for i in xrange(len(accounts)):
       for j in xrange(12):
           accounts[i] += round(accounts[i] * p/12.0, 2)
 
def evil_interest(accounts, p):
   my_account = 0.0
   for i in xrange(len(accounts)):
       for j in xrange(12):
           real_interest = accounts[i] * p/12.0
           interest_floor = floor(real_interest * 100.0)/100.0
           my_share = real_interest - interest_floor
           accounts[i] += interest_floor
           my_account += my_share
   return round(my_account, 2)
 
if __name__ == "__main__":
   from visual import rate, color
   from visual.graph import gdisplay, gcurve
 
   scene = display(                       
     title="How to succeed at business without really trying",
     autocenter=True                     
 
   gdisplay(                               # 2D graph window parameters
     title="Money Illegally Earned",     # Window title
     xtitle="Years",                     # Label on x-axis
     ytitle="Dollars",                   # Label on y-axis
     background=color.white,
     foreground=color.black
   )
 
   green_line = gcurve(color=(0,1,0))       # Set up a green curve
 
   accounts = create_accounts(100000)
   my_account = 0.0
 
   for i in xrange(25):
      my_account += evil_interest(accounts, 0.03)
      print "$", my_account
      green_line.plot(pos=(i, my_account))

Second Hour