# Collection of code snippets by Arne VajhÃ¸j 
# (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
# -*- coding: latin-1 -*-

from math import pow
from decimal import *

def round(x):
    x = Decimal(x).quantize(Decimal('.01'), rounding=ROUND_DOWN)
    return x

def myprint(s, i):
    print s, '{:>8}'.format(i)

def ncl(r, t, k, a):
    k = k + k * 0.02 + 600
    y = 0
    while(k > 0):
        y = y + 1
        if y / 12 >= t:
            print "Lånet er ikke holdbart"
            return
        termin = y % 12 == 0
        kr = k * r if termin else 0
        if k + kr < a:
            a = k + kr
        k = k + kr - a
        if termin:
            myprint("Termin nr:\t", y / 12)
        myprint("Måned:\t\t", y)
        if termin:
            myprint("Renten:\t\t", round(kr))
        myprint("Kapital:\t", round(k))
        myprint("Afdrag:\t\t", round(a))
        print
    print "Lånet er tilbagebetalt"
    return
 
ren = 0.11
ter = 10
kap = 15000
afd = 700

ncl(ren, ter, kap, afd)
