-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreditcalc.py
43 lines (32 loc) · 1.12 KB
/
creditcalc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import math
def payment(pricipal, months):
return int(math.ceil(pricipal/months))
def last(pricipal, months):
return principal - (months - 1)*payment(principal, months)
def month(principal, monthly):
a = principal//monthly
mod = principal%monthly
if mod == 0:
return a
else:
return a+1
def plural(principal, monthly):
a = principal/monthly
if a == 1:
return 'month'
else:
return 'months'
principal = int(input("Enter the loan principal:"))
print("What do you want to calculate?")
print('type "m" - for number of monthly payments,')
print('type "p" - for the monthly payment:')
choice = input()
if choice == 'm':
monthly = int(input("Enter the monthly payment:"))
print("It will take", month(principal, monthly), plural(principal, monthly), "to repay the loan")
elif choice == 'p':
months = int(input("Enter the number of months:"))
if principal%months == 0:
print("Your monthly payment =", payment(principal, months))
else:
print("Your monthly payment =", payment(principal, months), "and the last payment =", last(principal, months))