Python Forum

Full Version: Need help with print error
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello all. I'm totally new into Python learning journey and am stuck here, any thoughts what I'm missing here? I'm getting error with print saying invalid syntax

loan = 100000 
interest = 0.05 
pn = 30 

monthlypayment = loan[interest(1+interest)(pn)/[(1+interest)(pn)-1]
#print(monthlypayment)
The "[]" are usually used to call upon stuff from lists and dicts, that is most likely the syntax. Also if you are trying to multiply the variables, use "*". That is what's probably also giving you a syntax error
There is uneven open to close [] giving a invalid syntax, () & [] in python do special things you cant just copy a maths formula M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1] as close as you can.

loan = 100000 
interest = 0.05 
pn = 30 
 
# monthlypayment = loan[interest(1+interest)(pn)/[(1+interest)(pn)-1]
# M = P [ i(1 + i)^n ] / [ (1 + i)^n – 1]
monthlypayment = loan * (interest * (1 + interest) ** pn) / ((1 + interest) ** pn - 1)

print(monthlypayment)
Output:
6505.143508027656