Welcome, Guest: Register On Nairaland / LOGIN! / Trending / Recent / New
Stats: 3,154,051 members, 7,821,619 topics. Date: Wednesday, 08 May 2024 at 03:51 PM

Python Gurus Please Help Me With This Code. - Programming - Nairaland

Nairaland Forum / Science/Technology / Programming / Python Gurus Please Help Me With This Code. (695 Views)

Python Gurus In The House Help With This Questions / New To Python, Gurus Please Help Solve These Challenges. Thanks. / Java Gurus Please I Need This Little Assignment Solved ''appreciation Involved" (2) (3) (4)

(1) (Reply) (Go Down)

Python Gurus Please Help Me With This Code. by olamidedivotee(f): 9:01am On Jun 29, 2020
Grandlord
brukx


Python gurus where are you, help me with this


This code have been giving me sleepless night.



class Loan:
def __init__(self, annualInterestRate = 2.5,
numberOfYears = 1, loanAmount = 1000, borrower = " "wink:
self.__annualInterestRate = annualInterestRate
self.__numberOfYears = numberOfYears
self.__loanAmount = loanAmount
self.__borrower = borrower

def getAnnualInterestRate(self):
return self.__annualInterestRate

def getNumberOfYears(self):
return self.__numberOfYears

def getLoanAmount(self):
return self.__loanAmount

def getBorrower(self):
return self.__borrower

def setAnnualInterestRate(self, annualInterestRate):
self.__annualInterestRate = annualInterestRate

def setNumberOfYears(self, numberOfYears):
self.__numberOfYears = numberOfYears

def setLoanAmount(self, loanAmount):
self.__loanAmount = loanAmount

def setBorrower(self, borrower):
self.__borrower = borrower

def getMonthlyPayment(self):
monthlyInterestRate = self.__annualInterestRate / 1200
monthlyPayment = \
self.__loanAmount * monthlyInterestRate / (1 - (1 /
(1 + monthlyInterestRate) ** (self.__numberOfYears * 12)))
return monthlyPayment

def getTotalPayment(self):
totalPayment = self.getMonthlyPayment() * \
self.__numberOfYears * 12
return totalPayment

Re: Python Gurus Please Help Me With This Code. by stanliwise(m): 9:05am On Jun 29, 2020
Your indentation is wrong.
Learn how to arrange your python code properly.
Re: Python Gurus Please Help Me With This Code. by Brukx(m): 9:26am On Jun 29, 2020
olamidedivotee:
Grandlord
brukx


Python gurus where are you, help me with this


This code have been giving me sleepless night.



class Loan:
def __init__(self, annualInterestRate = 2.5,
numberOfYears = 1, loanAmount = 1000, borrower = " "wink:
self.__annualInterestRate = annualInterestRate
self.__numberOfYears = numberOfYears
self.__loanAmount = loanAmount
self.__borrower = borrower

def getAnnualInterestRate(self):
return self.__annualInterestRate

def getNumberOfYears(self):
return self.__numberOfYears

def getLoanAmount(self):
return self.__loanAmount

def getBorrower(self):
return self.__borrower

def setAnnualInterestRate(self, annualInterestRate):
self.__annualInterestRate = annualInterestRate

def setNumberOfYears(self, numberOfYears):
self.__numberOfYears = numberOfYears

def setLoanAmount(self, loanAmount):
self.__loanAmount = loanAmount

def setBorrower(self, borrower):
self.__borrower = borrower

def getMonthlyPayment(self):
monthlyInterestRate = self.__annualInterestRate / 1200
monthlyPayment = \
self.__loanAmount * monthlyInterestRate / (1 - (1 /
(1 + monthlyInterestRate) ** (self.__numberOfYears * 12)))
return monthlyPayment

def getTotalPayment(self):
totalPayment = self.getMonthlyPayment() * \
self.__numberOfYears * 12
return totalPayment

There's error in indentation
Re: Python Gurus Please Help Me With This Code. by Taofeekdboy(m): 9:26am On Jun 29, 2020
First, your code is too verbose, using class is an overkill for this mortgage calculator.
You can use function but it is fine if you really wanna use class but note that when defining a class, your method indentation must be accurate, like everything must be lined up together, press backspace for everything under the class and use tab key to indent them once.
Re: Python Gurus Please Help Me With This Code. by olamidedivotee(f): 9:35am On Jun 29, 2020
Taofeekdboy:
First, your code is too verbose, using class is an overkill for this mortgage calculator.
You can use function but it is fine if you really wanna use class but note that when defining a class, your method indentation must be accurate, like everything must be lined up together, press backspace for everything under the class and use tab key to indent them once.
I will try that
Re: Python Gurus Please Help Me With This Code. by SpacehubTech: 9:44am On Jun 29, 2020
Indentation gone wrong
Re: Python Gurus Please Help Me With This Code. by Taofeekdboy(m): 9:48am On Jun 29, 2020
olamidedivotee:

I will try that
Op, try also to learn how to debug as this is a powerful tool in programming, TypeError, ValidationError, ValueError, IndentationError, KeyError should be something you should be familiar with so that you can figure it out yourself and know whats wrong.
Re: Python Gurus Please Help Me With This Code. by olamidedivotee(f): 9:51am On Jun 29, 2020
Taofeekdboy:

Op, try also to learn how to debug as this is a powerful tool in programming, TypeError, ValidationError, ValueError, IndentationError, KeyError should be something you should be familiar with so that you can figure it out yourself and know whats wrong.
Okay

I'll do it later in the evening.
I've headache now from modularizing codes to this one.
Re: Python Gurus Please Help Me With This Code. by Grandlord: 10:42am On Jun 29, 2020
olamidedivotee:
Grandlord
brukx


Python gurus where are you, help me with this


This code have been giving me sleepless night.



class Loan:
def __init__(self, annualInterestRate = 2.5,
numberOfYears = 1, loanAmount = 1000, borrower = " "wink:
self.__annualInterestRate = annualInterestRate
self.__numberOfYears = numberOfYears
self.__loanAmount = loanAmount
self.__borrower = borrower

def getAnnualInterestRate(self):
return self.__annualInterestRate

def getNumberOfYears(self):
return self.__numberOfYears

def getLoanAmount(self):
return self.__loanAmount

def getBorrower(self):
return self.__borrower

def setAnnualInterestRate(self, annualInterestRate):
self.__annualInterestRate = annualInterestRate

def setNumberOfYears(self, numberOfYears):
self.__numberOfYears = numberOfYears

def setLoanAmount(self, loanAmount):
self.__loanAmount = loanAmount

def setBorrower(self, borrower):
self.__borrower = borrower

def getMonthlyPayment(self):
monthlyInterestRate = self.__annualInterestRate / 1200
monthlyPayment = \
self.__loanAmount * monthlyInterestRate / (1 - (1 /
(1 + monthlyInterestRate) ** (self.__numberOfYears * 12)))
return monthlyPayment

def getTotalPayment(self):
totalPayment = self.getMonthlyPayment() * \
self.__numberOfYears * 12
return totalPayment
Big boy, use the nairaland code tags around your code so we can see where the indentation error occurred. Or better still take a shot of it on your PC.

1 Like

Re: Python Gurus Please Help Me With This Code. by Grandlord: 10:45am On Jun 29, 2020
Taofeekdboy:
First, your code is too verbose, using class is an overkill for this mortgage calculator.
You can use function but it is fine if you really wanna use class but note that when defining a class, your method indentation must be accurate, like everything must be lined up together, press backspace for everything under the class and use tab key to indent them once.
I think maybe he wants to get used to OOP, ASAP, which isn't bad.
Re: Python Gurus Please Help Me With This Code. by Arg0n(m): 10:51am On Jun 29, 2020
Always be consistent with your Indenting in python. If its tab ure using, use it throughout the code. The same goes when ure using 4 spaces...

Also, Whenever u copy and paste a code, always re-indent it to avoid such errors.
Re: Python Gurus Please Help Me With This Code. by Goldeno(m): 11:10am On Jun 29, 2020
1st --Your code is too verbose

2nd-- there is error in indentation

Note: the error might not necessarily be on that specific line, so go through the code from bottom up, and use the '#' to silence any code or block of code that's OK, like I said from bottom upwards.
sometimes the error on a line might be related to the previous line.
Re: Python Gurus Please Help Me With This Code. by gbolly1151(m): 11:52am On Jun 29, 2020
Area where i think should improve on is how to use @property decorator to change the behavior of getter methods where necessary, remove setter method where not needed and the class will be perfect. Just my few cents
Re: Python Gurus Please Help Me With This Code. by Brukx(m): 11:57am On Jun 29, 2020
Grandlord:
Big boy, use the nairaland code tags around your code so we can see where the indentation error occurred. Or better still take a shot of it on your PC.
Show us how
Re: Python Gurus Please Help Me With This Code. by gbolly1151(m): 12:02pm On Jun 29, 2020
Brukx:

Show us how

[Code]
[/code]

Change C to c


Example

class hello:
pass
Re: Python Gurus Please Help Me With This Code. by Brukx(m): 12:04pm On Jun 29, 2020
gbolly1151:


[Code]
[/code]

Change C to c


Example

class hello:
pass


Thanks
Re: Python Gurus Please Help Me With This Code. by kensmoney(m): 12:25pm On Jun 29, 2020
stanliwise:
Your indentation is wrong.
Learn how to arrange your python code properly.
check your indentation in line 40
Re: Python Gurus Please Help Me With This Code. by Grandlord: 12:51pm On Jun 29, 2020
Brukx:

Show us how
[code][/code]
Re: Python Gurus Please Help Me With This Code. by Brukx(m): 8:17pm On Jun 29, 2020
olamidedivotee:
Grandlord
brukx


Python gurus where are you, help me with this


This code have been giving me sleepless night.




class Loan:
def __init__(self, annualInterestRate = 2.5,
numberOfYears = 1, loanAmount = 1000, borrower = " "wink:
self.__annualInterestRate = annualInterestRate
self.__numberOfYears = numberOfYears
self.__loanAmount = loanAmount
self.__borrower = borrower

def getAnnualInterestRate(self):
return self.__annualInterestRate

def getNumberOfYears(self):
return self.__numberOfYears

def getLoanAmount(self):
return self.__loanAmount

def getBorrower(self):
return self.__borrower

def setAnnualInterestRate(self, annualInterestRate):
self.__annualInterestRate = annualInterestRate

def setNumberOfYears(self, numberOfYears):
self.__numberOfYears = numberOfYears

def setLoanAmount(self, loanAmount):
self.__loanAmount = loanAmount

def setBorrower(self, borrower):
self.__borrower = borrower

def getMonthlyPayment(self):
monthlyInterestRate = self.__annualInterestRate / 1200
monthlyPayment = \
self.__loanAmount * monthlyInterestRate / (1 - (1 /
(1 + monthlyInterestRate) ** (self.__numberOfYears * 12)))
return monthlyPayment

def getTotalPayment(self):
totalPayment = self.getMonthlyPayment() * \
self.__numberOfYears * 12
return totalPayment




As you can see, only your first and last function are properly indented. That's the issue
Re: Python Gurus Please Help Me With This Code. by olamidedivotee(f): 9:11pm On Jun 29, 2020
Brukx:


As you can see, only your first and last function are properly indented. That's the issue
I've done it

(1) (Reply)

Anyone Knows A Wordpress Plugin For Live Streaming From Obs To Wordpress / My Third Tableau Dash-board Today / New To Programming

(Go Up)

Sections: politics (1) business autos (1) jobs (1) career education (1) romance computers phones travel sports fashion health
religion celebs tv-movies music-radio literature webmasters programming techmarket

Links: (1) (2) (3) (4) (5) (6) (7) (8) (9) (10)

Nairaland - Copyright © 2005 - 2024 Oluwaseun Osewa. All rights reserved. See How To Advertise. 30
Disclaimer: Every Nairaland member is solely responsible for anything that he/she posts or uploads on Nairaland.