Inherited class में एक method जोड़ें
आइए MortgageCalculator में एक method जोड़ते हैं जो दिए गए principal amount, वार्षिक ब्याज दर, और ऋण चुकाने के वर्षों की संख्या के आधार पर मासिक भुगतान की गणना करे।
यह अभ्यास पाठ्यक्रम का हिस्सा है
केस स्टडी: Python में सॉफ्टवेयर बनाना
इंटरैक्टिव व्यावहारिक अभ्यास
इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।
class MortgageCalculator(FinancialCalculator):
def __init__(self, loan_amount, annual_interest_rate, years):
super().__init__()
self.loan_amount = loan_amount
self.monthly_interest_rate = self.monthly_interest(annual_interest_rate)
self.months = self.multiply(years, 12)
self.monthly_payment = self.calculate_monthly_payment()
def calculate_monthly_payment(self):
numerator = self.monthly_interest_rate * (1 + self.monthly_interest_rate) ** self.months
denominator = (1 + self.monthly_interest_rate) ** self.months - 1
# Compute the quotient of numerator and denominator and save the result to multiplier
multiplier = self.divide(____, ____)