Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Start by getting the Listing 10.11 LoanCalculator.py program running: from tkinter import * # Import tkinter class LoanCalculator: def __init__(self): window = Tk() # Create
Start by getting the Listing 10.11 LoanCalculator.py program running: from tkinter import * # Import tkinter class LoanCalculator: def __init__(self): window = Tk() # Create a window window.title("Loan Calculator") # Set title Label(window, text = "Annual Interest Rate"). grid row = 1, column = 1, sticky = W) Label(window, text = "Number of Years").grid(row = 2, column = 1, sticky = W) Label(window, text = "Loan Amount")-grid(row = 3, column = 1, sticky = W) Label(window, text = "Monthly Payment").grid(row = 4, column = 1, sticky = W) Label(window, text = "Total Payment")-grid(row = 5, column = 1, sticky = W) self.annualInterestRatevar = FILL_CODE_OR_CLICK_ANSWER Entry(window, textvariable = self.annualInterestRatevar, justify = RIGHT)-grid(row = 1, column = 2) self.numberOfYearsVar = Stringvar() Entry(window, FILL_CODE_OR_CLICK_ANSWER, justify = RIGHT) grid(row = 2, column = 2) self.loanAmountVar = Stringvar() Entry(window, textvariable = self.loanAmountVar, justify = RIGHT)-grid(row = 3, column = 2) self.monthlyPaymentvar = Stringvar) 1b1MonthlyPayment = Label(window, textvariable = self.monthlyPaymentVar)-grid(row = 4, column = 2, sticky = E) self.totalPaymentVar = StringVar() lblTotalPayment = Label(window, textvariable = self.totalPaymentVar) grid(row = 5, column = 2, sticky = E) btComputePayment - Button(window, text = "Compute Payment", command = FILL_CODE_OR_CLICK_ANSWER)-grid row = 6, column = 2, sticky = E) window.mainloop() # Create an event loop def computePayment(self): monthlyPayment = self.getMonthlyPayment float(self. loanAmountVar.get(), float(self.annualInterestRateVar.get() / 1200, int(FILL_CODE_OR_CLICK_ANSWER)) self.monthlyPaymentVar.set(format(monthlyPayment, '10.2'), totalPayment = float(self.monthlyPaymentvar.get() - 12 * int(self.numberOfYearsVar.get() self.totalPaymentVar.set(format(totalPayment, '10.27')) def getMonthlyPayment(self, loanAmount, monthlyInterestRate, numberOfYears): monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1/ (1 + monthlyInterestRate) ** (numberOfYears - 12) return monthlyPayment; LoanCalculator() # Create GUI The execution window looks as follows: - 0 X 3.8 Loan Calcu. Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment 30 450000 2096.81 754851.60 Compute Payment Modify the program to provide another input for a revised monthly payment, and output for a revised loan amount. The Compute Loan Amount button will compute a new Loan amount using the adjusted monthly payment, but using the same interest rate and number of years: Enhanced Loan Cal. - O X 30 Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment 450000 2096.81 754851.60 Compute Payment Monthly Payment Loan Amount 2400 515068.60 Compute Loan Amount To get full credit, add spacing around the outside of the form and between the Compute Payment button and the Monthly Payment Entry box. You accomplish this by adding grid rows and columns containing spaces, The following two methods should help: def computeLoan(self): loanAmount2 = self.getLoanAmount(float(self.monthlyPaymentvar2.get(), float(self.annualInterestRateVar.get())/ 1200, int(self. numberOfYearsvar.get()) self.loanAmountVar2.set(format(loanAmount2, "10.2f')) def getLoanAmount (self, monthlyPayment, monthlyInterestRate, numberOfYears): loanAmount = monthlyPayment * (1 - 1 / (1 + monthlyInterestRate) ** (numberOfYears - 12)) / monthlyInterestRate return loanAmount; Add your name as a comment in the program and attach it below. Start by getting the Listing 10.11 LoanCalculator.py program running: from tkinter import * # Import tkinter class LoanCalculator: def __init__(self): window = Tk() # Create a window window.title("Loan Calculator") # Set title Label(window, text = "Annual Interest Rate"). grid row = 1, column = 1, sticky = W) Label(window, text = "Number of Years").grid(row = 2, column = 1, sticky = W) Label(window, text = "Loan Amount")-grid(row = 3, column = 1, sticky = W) Label(window, text = "Monthly Payment").grid(row = 4, column = 1, sticky = W) Label(window, text = "Total Payment")-grid(row = 5, column = 1, sticky = W) self.annualInterestRatevar = FILL_CODE_OR_CLICK_ANSWER Entry(window, textvariable = self.annualInterestRatevar, justify = RIGHT)-grid(row = 1, column = 2) self.numberOfYearsVar = Stringvar() Entry(window, FILL_CODE_OR_CLICK_ANSWER, justify = RIGHT) grid(row = 2, column = 2) self.loanAmountVar = Stringvar() Entry(window, textvariable = self.loanAmountVar, justify = RIGHT)-grid(row = 3, column = 2) self.monthlyPaymentvar = Stringvar) 1b1MonthlyPayment = Label(window, textvariable = self.monthlyPaymentVar)-grid(row = 4, column = 2, sticky = E) self.totalPaymentVar = StringVar() lblTotalPayment = Label(window, textvariable = self.totalPaymentVar) grid(row = 5, column = 2, sticky = E) btComputePayment - Button(window, text = "Compute Payment", command = FILL_CODE_OR_CLICK_ANSWER)-grid row = 6, column = 2, sticky = E) window.mainloop() # Create an event loop def computePayment(self): monthlyPayment = self.getMonthlyPayment float(self. loanAmountVar.get(), float(self.annualInterestRateVar.get() / 1200, int(FILL_CODE_OR_CLICK_ANSWER)) self.monthlyPaymentVar.set(format(monthlyPayment, '10.2'), totalPayment = float(self.monthlyPaymentvar.get() - 12 * int(self.numberOfYearsVar.get() self.totalPaymentVar.set(format(totalPayment, '10.27')) def getMonthlyPayment(self, loanAmount, monthlyInterestRate, numberOfYears): monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1/ (1 + monthlyInterestRate) ** (numberOfYears - 12) return monthlyPayment; LoanCalculator() # Create GUI The execution window looks as follows: - 0 X 3.8 Loan Calcu. Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment 30 450000 2096.81 754851.60 Compute Payment Modify the program to provide another input for a revised monthly payment, and output for a revised loan amount. The Compute Loan Amount button will compute a new Loan amount using the adjusted monthly payment, but using the same interest rate and number of years: Enhanced Loan Cal. - O X 30 Annual Interest Rate Number of Years Loan Amount Monthly Payment Total Payment 450000 2096.81 754851.60 Compute Payment Monthly Payment Loan Amount 2400 515068.60 Compute Loan Amount To get full credit, add spacing around the outside of the form and between the Compute Payment button and the Monthly Payment Entry box. You accomplish this by adding grid rows and columns containing spaces, The following two methods should help: def computeLoan(self): loanAmount2 = self.getLoanAmount(float(self.monthlyPaymentvar2.get(), float(self.annualInterestRateVar.get())/ 1200, int(self. numberOfYearsvar.get()) self.loanAmountVar2.set(format(loanAmount2, "10.2f')) def getLoanAmount (self, monthlyPayment, monthlyInterestRate, numberOfYears): loanAmount = monthlyPayment * (1 - 1 / (1 + monthlyInterestRate) ** (numberOfYears - 12)) / monthlyInterestRate return loanAmount; Add your name as a comment in the program and attach it below
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started