Search code examples
pythonpython-2.7line-breaks

How to do a line break in python?


this is my first question on stackoverflow. I'm trying to do problem sets on OCW online classes in Python, and I don't know how to debug my code. I work with IDLE, and Python 2.7.

Here is my code:

balance = float(raw_input("Enter the outstanding balance on your credit card: "))
annual_itst = float(raw_input("Enter the annual credit card interest rate as a decimal: "))
min_paymt_rate = float(raw_input("Enter the minimum monthly payment rate as a decimal: "))

remaining_balance = balance

for i in range(1,13):
    min_monthly_paymt=min_paymt_rate*remaining_balance
    inst_paid = (annual_itst / 12.0 )*remaining_balance
    pcpl_paid = min_monthly_pamt - inst_paid
    remaining_balance -= pcpl_paid

print("Month: " & i, \n "Minimum monthly payment: " & "$" & round(min_monthly_paymt, 2), \n "Principle paid: " & "$" & round(pcpl_paid, 2),
      \n "Remaining balance: " & "$" & round(remaining_balance, 2))

When I execute it, I have a message error "unexpected character after line continuation character" with a red highlight just after the first line in the print function. Thank you for your help !


Solution

  • Here it is, learn about operators and formatting to print output

    balance = float(raw_input("Enter the outstanding balance on your credit card: "))
    annual_itst = float(raw_input("Enter the annual credit card interest rate as a decimal: "))
    min_paymt_rate = float(raw_input("Enter the minimum monthly payment rate as a decimal: "))
    
    remaining_balance = balance
    
    for i in range(1,13):
        min_monthly_paymt=min_paymt_rate*remaining_balance
        inst_paid = (annual_itst / 12.0 )*remaining_balance
        pcpl_paid = min_monthly_paymt - inst_paid
        remaining_balance -= pcpl_paid
    print "\n\n\n"
    print "Month: {}".format(i), '\n',"Minimum monthly payment: $ {}".format(round(min_monthly_paymt, 2)), '\n',"Principle paid:$ ".format(round(pcpl_paid, 2)),'\n',"Remaining balance: $".format(round(remaining_balance, 2))