1
+ CODE :-
2
+
3
+ import math
4
+
5
+ def interest ():
6
+ return float (input ("Enter the credit interest: " )) / (12 * 100 )
7
+
8
+ def n_of_payments ():
9
+ P = float (input ("Enter the credit principal: " ))
10
+ A = float (input ("Enter the monthly payment: " ))
11
+ i = interest ()
12
+ return math .log (A / (A - i * P ), 1 + i )
13
+
14
+ def credit_principal ():
15
+ A = float (input ("Enter the monthly payment: " ))
16
+ n = float (input ("Enter the count of periods: " ))
17
+ i = interest ()
18
+ return A / ((i * math .pow (1 + i , n )) / (math .pow (1 + i , n ) - 1 ))
19
+
20
+ def annuity_payment ():
21
+ P = float (input ("Enter the credit principal: " ))
22
+ n = float (input ("Enter the number of periods: " ))
23
+ i = interest ()
24
+ return P * ((i * math .pow (1 + i , n )) / (math .pow (1 + i , n ) - 1 ))
25
+
26
+
27
+ calc_type = input ("""What do you want to calculate?
28
+ type "n" for the number of months,
29
+ type "a" for the annuity monthly payment,
30
+ type "p" for the credit principal:
31
+ """ )
32
+
33
+ if calc_type == "n" :
34
+ months = math .ceil (n_of_payments ())
35
+ years = 0
36
+ if months == 12 :
37
+ print ("You need 1 year to repay this credit!" )
38
+ elif months > 12 :
39
+ years = months // 12
40
+ months = months % 12
41
+ if months == 1 :
42
+ print (f"You need { years } years and 1 month to repay this credit!" )
43
+ else :
44
+ print (f"You need { years } years and { months } months to repay this credit!" )
45
+ else :
46
+ if months == 1 :
47
+ print (f"You need 1 months to repay this credit!" )
48
+ else :
49
+ print (f"You need { months } months to repay this credit!" )
50
+ elif calc_type == "a" :
51
+ print (f"Your annuity payment = { math .ceil (annuity_payment ())} !" )
52
+ elif calc_type == "p" :
53
+ print (f"Your credit principal = { round (credit_principal ())} !" )
0 commit comments