thedonace213
thedonace213

Reputation: 1

Basic mortgage calculator

So I'm a beginner and I am trying to make a simple mortgage calculator. This is my code:

L=input('Enter desired Loan amount: ')
I=input('Enter Interest Rate: ')
N=input('Enter time length of loan in months: ')

MonthlyPayments= [float(L)*float(I)*(1+float(I))*float(N)]/((1+float(I))*float(N)-1)


print('Your Monthly Payments will be {0:.2f}'.format(MonthlyPayments))`

and i get an error that says: unsupported operand type(s) for /: 'list' and 'float'

Upvotes: 0

Views: 859

Answers (3)

Chad S.
Chad S.

Reputation: 6633

Firstly using square brackets will create a list which is probably not what you want. Also to avoid having to convert constantly you can (and should) wrap your input calls with the type you're expecting to get.

So to go from your example code, I would write it thusly:

L=float(input('Enter desired Loan amount: '))
I=float(input('Enter Interest Rate: '))
N=float(input('Enter time length of loan in months: '))

MonthlyPayments = (L*I*(1+I)*N)/((1+I)*N-1)

print('Your Monthly Payments will be {0:.2f}'.format(MonthlyPayments))

This also makes it easier to read

Upvotes: 1

Gocht
Gocht

Reputation: 10256

Here:

MonthlyPayments = [float(L)*float(I)*(1+float(I))*float(N)]/((1+float(I))*float(N)-1)

This part:

[float(L)*float(I)*(1+float(I))*float(N)]

Gives a 'list' data type. Replace [] by ()

Upvotes: 0

mksteve
mksteve

Reputation: 13085

 MonthlyPayments= (float(L)*float(I)*(1+float(I))*float(N))/((1+float(I))*float(N)-1)

'[' and ']' create a list.

Upvotes: 0

Related Questions