Question: Python Consider the following class definition: class Account(object): Represent a bank account. Argument: account_holder (string): account holder's name. Attributes: holder (string): account holder's name.
Python
Consider the following class definition:
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
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:
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 You only need to include the property definition in your answer.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
