All pastes #801332 Raw Edit

k4st

public python v1 · immutable
#801332 ·published 2007-11-29 04:49 UTC
rendered paste body
def scholarship_1(initial_amount=15000, skip_years=4, ir=0.06, 		sr=(lambda n:0.03), it=10):	"""Calculate and output the scholarship payouts (among other things)	given an interest rate and a scholarship rate function."""	total = initial_amount * ((1+ir)**(skip_years-1))	# we start from *just* before the fourth year's interest earnings	for n in range(0, it):		scholarship = sr(n) * total		interest = ir * total		total = total - scholarship + interest		print "year: %d\nn: %d\ninterest: %f\nscholarship: %f\nleft over:" \					"%f\n\n" % (n+4, n, interest, scholarship, total)def scholarship_2(initial_amount=15000, skip_years=4, ir=0.06, 		sr=(lambda n:0.03), it=10):	"""Calculate and output the scholarship payouts (among other things)	given an interest rate and a scholarship rate function."""	total = initial_amount * ((1+ir)**(skip_years-1))		for n in range(0, it):		total = (1+ir) * total		scholarship = sr(n) * total		total -= scholarship		print "year: %d\nn: %d\nscholarship: %f\nleft over:" \					"%f\n\n" % (n+4, n, scholarship, total)	if __name__ == "__main__":	print "method one: interest calculation, then scholarship, then deduct.\n"	scholarship_1(sr=lambda n: (0.03 + (0.03 * n)), it=1)		print "method two: calculate interest, add, calculate scholarship, deduct\n"	scholarship_2(sr=lambda n: (0.03 + (0.03 * n)), it=1)