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