Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d3c1999

Browse files
Add files via upload
1 parent 4155182 commit d3c1999

File tree

1 file changed

+52
-0
lines changed

1 file changed

+52
-0
lines changed
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /