0

So, i know this is so basic, but i'm getting this error: What can i do to repair this? y.y

Traceback (most recent call last): File "/home/coding/Documents/Python Repository/2 - Numbers & math (Loan Calclator).py", line 40, in monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0] TypeError: can't multiply sequence by non-int of type 'float'

#Loan Calculator

#Monthly Payments formula > M = L[i(1+i)n] / [(1+i)n-1]
# M = Month Payment
# L = Loan amount
# i = interest rate (int rate of 5%, i = 0.05)
# n = number of payments


print ('Hey there! Welcome to Johnny\'s Loan Bank!')

#just set variable
monthly_payment = 0

#Set how much money user will need
loan_input = input('So, how much would you like to lend? ')

#transform the input in a float
loan_amount = float(loan_input)


#Set number of months to pay
num_of_pay_input = input('And in how many months would you like to pay? ')

#transform value into a float
num_of_payments = float(num_of_pay_input)

print ('\nSo, you want to lend {0:.1f} in {1:.1f} payments'.format(loan_amount, num_of_payments))
print ('You should know that we work with an interest rate of 5%')

#Variable set to know the users decision
user_decision = input('Would you like to continue?: ')
print (user_decision)

if user_decision == 'y' or decision == 'yes':
    print ('loan_amount {0:.1f}'.format(loan_amount))
    print ('num_of_payments {0:.1f}'.format(num_of_payments))

Line 40>>>>     monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0]

    print ('Ok, you\'ll get a loan of {0:.1f} and you gonna pay us in {1:.1f} months'.format(loan_amount, num_of_payments) + \
        ', thats gonna be {0:.1f} for month.'.format(monthly_payment))
else:
    print ('get off my bank')
2
  • 1
    the code [0.05 * (1.0 + 0.05) * float(num_of_payments)] is creating a list of length one containing a single float, which you are attempting to multiply by a float. You probably mean to do (0.05 * (1.0 + 0.05) * float(num_of_payments)), which will just create a float Commented Jun 17, 2016 at 0:20
  • OMG hahahaha i knew it was simple.. Thanks a lot. I'm started coding for a few days, thats something i didnt realized. really appreciate your help, tks! Commented Jun 17, 2016 at 0:27

1 Answer 1

6

In your line:

    monthly_payment = float(loan_amount) * [0.05 * (1.0 + 0.05) * float(num_of_payments)] / [(1.0 + 0.05) * float(num_of_payments) - 1.0]

You are using square brackets (in this case used to create a list) as a means of specifying order of operations. This should be () type brackets.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.