Mar-27-2020, 03:17 AM
Hi all,
Thank you in advance for giving this a read. I have completed 99.9% of this assignment.
The goal of the program is to ask user to enter 'Car purchased price' and how many loan term years (only two options 2or3 years). The only error I get is when the user inputs the wrong loan term
The 'If else' syntax works until the user enters the wrong loan term year. My assumption is that the program keeps executing therefore I get this traceback error.
I'm using IDLE 3.8.1. Also, there is a definitely a different approach to this code but we are constrained to what we've learned in chp1-chp5 in class.
Thank you in advance for giving this a read. I have completed 99.9% of this assignment.
The goal of the program is to ask user to enter 'Car purchased price' and how many loan term years (only two options 2or3 years). The only error I get is when the user inputs the wrong loan term
Error:Traceback (most recent call last):
File "*****/****/****/****/HW#2Q1.py", line 49, in <module>
endingB = initialBalance - installment
NameError: name 'installment' is not defined
My goal is to have a loop or have the program end if the user enters the wrong loan term year. The 'If else' syntax works until the user enters the wrong loan term year. My assumption is that the program keeps executing therefore I get this traceback error.
I'm using IDLE 3.8.1. Also, there is a definitely a different approach to this code but we are constrained to what we've learned in chp1-chp5 in class.
#CONSTANTS APR=0.06 DOWN_PAYMENT=0.10 MONTH=1 YEAR=1 #input from user purchasePrice=float(input('Enter Car Purchased Price:$')) loanTerm=int(input('Enter Loan Terms (2 or 3 yrs):')) #headings titleMonth='Month' titleYear='Year' titleIB='Starting Balance' titleI='Installment' titleEB='Ending Balance' titleRIM='Remaining Installments' #downpayment calculation downPayment=purchasePrice * DOWN_PAYMENT #initialbalance calculation initialBalance=(purchasePrice - downPayment) + ((purchasePrice - downPayment)*APR*(loanTerm)) #installment payments if loanTerm == 2 : installment=(initialBalance/24) elif loanTerm==3: installment=(initialBalance/36) else: print('Error: Please enter correct Loan Term:=') #installmentleft resultIM = int(loanTerm* 12) #printing Headers print('%-20s %-10s %-20s %-20s %-20s %s' %(titleMonth,titleYear,titleIB,titleI,titleEB,titleRIM)) #while loop calculation while MONTH <= (loanTerm * 12): endingB = initialBalance - installment print('%-20s %-10s %-20s %-20s %-20s %s' %(MONTH,YEAR,initialBalance,installment,endingB,resultIM)) initialBalance=endingB YEAR= int(MONTH/12)+1 resultIM = resultIM - 1 MONTH = MONTH+1