File: mortgage.py

package info (click to toggle)
pythoncard 0.8.2-2
  • links: PTS
  • area: main
  • in suites: wheezy
  • size: 8,452 kB
  • sloc: python: 56,787; makefile: 56; sh: 22
file content (36 lines) | stat: -rw-r--r-- 1,270 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/python

"""
A mortgage repayment calculator. Used in the presentation at VanPy 2005 and PyCon 2005.

Subsequently borrowed for the presentation at OSDC 2005 
"""
__version__ = "$Revision: 1.2 $"
__date__ = "$Date: 2005/12/13 11:13:22 $"

from PythonCard import dialog, model
import pyfi

class MyBackground(model.Background)

    def on_initialize(self, event):
        # if you have any initialization
        # including sizer setup, do it here
        self.on_Calculate_mouseClick(None)

    def on_Calculate_mouseClick(self, event):
        comp = self.components
        try:
            principal = float(comp.Principal.text)
            interestRate = float(comp.InterestRate.text)
            if interestRate > 1:
                interestRate = interestRate / 100.0
            payment15 = pyfi.amortization(principal, interestRate, 12, 15 * 12)
            payment30 = pyfi.amortization(principal, interestRate, 12, 30 * 12)
            comp.Result.text = "15 year monthly payment: %.2f\n30 year monthly payment: %.2f" % (payment15, payment30)
        except ValueError:
            dialog.alertDialog(self, 'Please enter valid values', 'Input Value(s) Error')

if __name__ == '__main__':
    app = model.Application(MyBackground)
    app.MainLoop()