how to calculate depreciation rate for straight line method python

Solutions on MaxInterview for how to calculate depreciation rate for straight line method python by the best coders in the world

showing results for - "how to calculate depreciation rate for straight line method python"
Maya
20 Sep 2018
1def sl(val,n):
2    deprec=val/n
3    print "in ",n
4    
5    for year in range(1,n+1):
6        val=val-deprec
7        writeoutput(year,deprec,val)
8
9    return
10
11def ddb(val,n):
12    for year in range(1,n+1):
13        deprec=2*val/n
14        val=val-deprec
15        writeoutput(year,deprec,val)
16
17    return
18
19def syd(val,n):
20    tag=val
21    for year in range(1,n+1):
22        deprec=(n-year+1)*tag/(n*(n+1)/2)
23        val=val-deprec
24        writeoutput(year,deprec,val)
25
26    return
27
28def writeoutput(year,depreciation,value):
29    print "End of the year %2d  Depreciation: %7.2f  Current Value: %8.2f" %(year,depreciation,value)
30
31    return
32
33
34
35def main(choice,val,n):
36    
37    print "Original value : ",val
38    val=float(val)
39    print "Number of years : ",n
40
41    if choice==1:
42        print "Straight-Line Method\n\n"
43        sl(val,n)
44    elif choice==2:
45        print "Double-Declining-Balance Method \n\n"
46        ddb(val,n)
47    elif choice==3:
48        print "Sum-Of-The-Years'-Digits Method"
49        syd(val,n)
50
51    return
52
53
54print "\n\nMethod: (1-SL 2-DDB 3-SYD)"
55main(1,8000,10)
56print "\n\nMethod: (1-SL 2-DDB 3-SYD)"
57main(2,8000,10)
58print "\n\nMethod: (1-SL 2-DDB 3-SYD)"
59main(3,8000,10)
60print "\n\nMethod: (1-SL 2-DDB 3-SYD)"
61main(1,5000,4)
62
63
64    
65    
66
similar questions