Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Python Consider the following class definition: The bank gives customers credit

ID: 3739314 • Letter: P

Question

Python

Consider the following class definition:

The bank gives customers credit up to a maximum amount equal to half of their current balance.

Write a property, credit_limit, for the Account class that returns the credit limit of the given account.

Do not modify __init__ and do not store the credit limit as an instance variable.

Once you implement the credit_limit property, you should be able to test it as follows:

You only need to include the property definition in your answer.   

Explanation / Answer

class Account(object): """ Represent a bank account. Argument: account_holder (string): account holder's name. Attributes: holder (string): account holder's name. balance (float): account balance in dollars. """ def __init__(self, account_holder): self.holder = account_holder self.balance = 0 def deposit(self, amount): """ deposit amount to the account Parameter: amount (float): the amount to be deposited in dollars. Returns: the updated account object """ self.balance += amount return self def withdraw(self, amount): """ withdraw the amount from the account if possible. Parameter: amount (float): the amount to be withdrawn in dollars. Returns: boolean: True if the withdrawal is successful False otherwise """ if self.balance >= amount: self.balance = self.balance - amount return True else: return False def get_balance(self): return self.balance @property def credit_limit(self): return self.balance / 2 if __name__ == '__main__': my_account = Account('Rula') my_account.deposit(100) print(my_account.credit_limit) # prints 50.0 my_account.deposit(501.50) print(my_account.credit_limit) # prints 300.75 c_account = Account('Charlie') c_account.deposit(12000) print(c_account.credit_limit) # prints 6000.0