Question

In: Computer Science

Can someone please fix my program? I keep getting a syntax error. Thanks (Python) from tkinter...

Can someone please fix my program? I keep getting a syntax error. Thanks (Python)

from tkinter import *

class LoanCalculator:
def __init__(self):
window = Tk()
window.title("Loan Calculator")

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 = StingVar()
Entry(window,textvariable = self.annualInterestRateVar,Justify=Right).grid(row = 1, column = 2)
self.numberofYearsvar = StringVar()
Entry(window,textvariable = self.numberofYearsVar,Justify=Right).grid(row = 2, column = 2)
self.loanAmountVar = StringVar()
Entry(window,textvariable = self.self.loanAmountVar,Justify=Right).grid(row = 3, column = 2)

self.monthlyPaymentVar = StringVar()
lblMonthlyPayment = Label(window,textvariable = self.monthlyPaymentVar)\
.grid(row = 5, 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 = self.computePayment).grid(row = 6, column = 2, sticky = E)

window.mainloop()

def computePayment(self):
try:
monthlyPayment = self.getMonthlyPayment(float(self.loanAmountVar.get()),\
float(self.annualInterestRateVar.get())/1200,\
int(self.numberOfYearsVar.get())
self.monthlyPaymentVar.set('%.2f' % monthlyPayment)
totalPayment = float(self.monthlyPaymentVar.get())*12 *int(self.numberOfYearsVar.get())
self.totalPaymentVar.set('%.2f' % totalPayment)

except:
self.totalPaymentVar.set("Error in input")

def getMonthlyPayment(self,loan,Amount,monthlyInterestRate,numberOfYears):
monthlyPayment = loanAmount * monthlyInterestRate/(1-1/ \
(1 + monthlyInterestRate)**(numberOfYears*12))
return monthlyPayment
  

def main():


LoanCalulator()

Solutions

Expert Solution

Here is code:

from tkinter import *


class LoanCalculator:

def __init__(self):

window = Tk()

window.title("Loan Calculator")

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 = StringVar()

Entry(window, textvariable=self.annualInterestRateVar, justify=RIGHT).grid(row=1, column=2)

self.numberOfYearsVar = StringVar()

Entry(window, textvariable=self.numberOfYearsVar, 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()

lblMonthlyPayment = 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=self.computePayment).grid(row=6, column=2, sticky=E)

window.mainloop()

def computePayment(self):

monthlyPayment = self.getMonthlyPayment(float(self.loanAmountVar.get()),

float(self.annualInterestRateVar.get()) / 1200,

int(self.numberOfYearsVar.get()))

self.monthlyPaymentVar.set(format(monthlyPayment, ".2f"))

totalPayment = float(self.monthlyPaymentVar.get()) * 12 * int(self.numberOfYearsVar.get())

self.totalPaymentVar.set(format(totalPayment, ".2f"))

def getMonthlyPayment(self, loanAmount, monthlyInterestRate, numberOfYears):

monthlyPayment = loanAmount * monthlyInterestRate / (1 - 1 / (1 + monthlyInterestRate) ** (numberOfYears * 12))

return monthlyPayment

def main():

LoanCalculator()

main()

Output:


Related Solutions

Please fix this python script, I keep getting a return outside function error and cannot get...
Please fix this python script, I keep getting a return outside function error and cannot get it to run: def caesar(plainText, shift):     cipherText = "" for char in plainText:     newChar = ord(char) + shift     if newChar > 128:       newChar = newChar % 128     finalChar = chr(newChar)     cipherText += finalChar return cipherText text = input("Enter a message: "); s = input("Enter the distance value: "); print (caesar(text, int(s)));
Python programming: can someone please fix my code to get it to work correctly? The program...
Python programming: can someone please fix my code to get it to work correctly? The program should print "car already started" if you try to start the car twice. And, should print "Car is already stopped" if you try to stop the car twice. Please add comments to explain why my code isn't working. Thanks! # Program goals: # To simulate a car game. Focus is to build the engine for this game. # When we run the program, it...
Syntax error in C. I am not familiar with C at all and I keep getting...
Syntax error in C. I am not familiar with C at all and I keep getting this one error "c error expected identifier or '(' before } token" Please show me where I made the error. The error is said to be on the very last line, so the very last bracket #include #include #include #include   int main(int argc, char*_argv[]) {     int input;     if (argc < 2)     {         input = promptUserInput();     }     else     {         input = (int)strtol(_argv[1],NULL, 10);     }     printResult(input);...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA...
I keep getting the error below in zbooks. How can I fix this. Thank You JAVA zyLabsUnitTest.java:14: error: cannot find symbol s = MidtermProblems.difference(75, 75); ^ symbol: method difference(int,int) location: class MidtermProblems 1 error import java.lang.Math; public class MidtermProblems { public static String difference(int a, int b) { int diff = Math.abs(a - b); String ans = "";    if (diff == 0) { ans = "EQUAL";    } else if (diff > 10) { ans = "Big Difference "...
C++ : Find the syntax errors in the following program. For each syntax error, fix it...
C++ : Find the syntax errors in the following program. For each syntax error, fix it and add a comment at the end of the line explaining what the error was. #include <iostream> #include <cmath> using namespace std; int main(){ Double a, b, c; 2=b; cout<<"Enter length of hypotenuse"<<endl; cin>>c>>endl; cout>>"Enter length of a side"<<endl; cin>>a; double intermediate = pow(c, 2)-pow(a, 2); b = sqrt(intermediate); cout<<"Length of other side is:" b<<endline; return 0; }
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in...
My code works in eclipse, but not in Zybooks. I keep getting this error. Exception in thread "main" java.util.NoSuchElementException at java.base/java.util.Scanner.throwFor(Scanner.java:937) at java.base/java.util.Scanner.next(Scanner.java:1478) at Main.main(Main.java:34) Your output Welcome to the food festival! Would you like to place an order? Expected output This test case should produce no output in java import java.util.Scanner; public class Main {    public static void display(String menu[])    {        for(int i=0; i<menu.length; i++)        {            System.out.println (i + " - " + menu[i]);...
I am getting 7 errors can someone fix and explain what I did wrong. My code...
I am getting 7 errors can someone fix and explain what I did wrong. My code is at the bottom. Welcome to the DeVry Bank Automated Teller Machine Check balance Make withdrawal Make deposit View account information View statement View bank information Exit          The result of choosing #1 will be the following:           Current balance is: $2439.45     The result of choosing #2 will be the following:           How much would you like to withdraw? $200.50      The...
This is in Python I am getting an error when I run this program, also I...
This is in Python I am getting an error when I run this program, also I cannot get any output. Please help! #Input Section def main(): name=input("Please enter the customer's name:") age=int(input("Enter age of the customer: ")) number_of_traffic_violations=int(input("Enter the number of traffic violations: ")) if age <=15 and age >= 105: print('Invalid Entry') if number_of_traffic_violations <0: print('Invalid Entry') #Poccessing Section def Insurance(): if age < 25 and number_of_tickets >= 4 and riskCode == 1: insurancePrice = 480 elif age >=...
HI. I have been trying to run my code but I keep getting the following error....
HI. I have been trying to run my code but I keep getting the following error. I can't figure out what I'm doing wrong. I also tried to use else if to run the area of the other shapes but it gave me an error and I created the private method. Exception in thread "main" java.util.InputMismatchException at java.base/java.util.Scanner.throwFor(Scanner.java:939) at java.base/java.util.Scanner.next(Scanner.java:1594) at java.base/java.util.Scanner.nextInt(Scanner.java:2258) at java.base/java.util.Scanner.nextInt(Scanner.java:2212) at project2.areacalculation.main(areacalculation.java:26) My code is below package project2; import java.util.Scanner; public class areacalculation { private static...
My program is working until it gets to val2 / 1000000. I keep getting my answer...
My program is working until it gets to val2 / 1000000. I keep getting my answer to be 0. Can someone help please? int main() {    int n, num, num1, num2, time, val1, val2, Ts;                printf("**** Welcome to the Time Study Program ****\n");    printf("\n");    printf("Enter the number of elements for the give operation being perform\n");    printf("Number of elements: ");    scanf_s("%d", &n);    printf("\n");    printf("Enter the Performance Rating (PR) factor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT