OneCompiler

urkurk c1

123
 class LoanManager:
#Constructor: no parameters.    
    def __init__(self):
        self.bank_loans = {}
        
#registers a loan application for a customer with the amount and interest rate (percentage). 
#Returns True if successful, False if the customer already has a loan.
    def apply_for_loan(self, customer, amount, interest_rate):
        if customer in self.bank_loans:
            return False
        else:
            self.bank_loans[customer] = amount + (amount * interest_rate)/100
            return True
        
#returns the total balance for a customer, including interest. 
#Returns "N/A" if the customer does not have a loan.
    def get_loan_balance(self, customer):
        if customer not in self.bank_loans:
            return 'N/A'
        else:
            return self.bank_loans[customer]
            
        
#reduces the loan balance for a customer by the payment amount. 
#Returns True if successful, False if the payment exceeds the balance 
#or if the customer does not have a loan.        
    def pay_loan(self, customer, payment):
        if customer not in self.bank_loans:
            return False
        
        balance = self.bank_loans[customer]
        
        if payment > balance:
            return False
            
        self.bank_loans[customer] -= payment
        
        if self.bank_loans <= 0:
            del self.bank_loans[customer]
            
        return True