diff --git a/lab-python-oop.ipynb b/lab-python-oop.ipynb index c13bc58..b58be7e 100644 --- a/lab-python-oop.ipynb +++ b/lab-python-oop.ipynb @@ -56,13 +56,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "21625526-3fae-4c55-bab5-f91940070681", "metadata": {}, "outputs": [], "source": [ "# your code goes here\n", - "\n" + "\n", + "class BankAccount:\n", + " account_count = 0 # Atributo de clase\n", + "\n", + " def _init_(self, balance=0):\n", + " self.balance = balance\n", + " BankAccount.account_count += 1\n", + " self.account_number = BankAccount.account_count\n", + "\n", + " def deposit(self, amount):\n", + " self.balance += amount\n", + "\n", + " def withdraw(self, amount):\n", + " if amount <= self.balance:\n", + " self.balance -= amount\n", + " else:\n", + " print(\"Insufficient balance\")\n", + "\n", + " def get_balance(self):\n", + " return self.balance\n", + "\n", + " def get_account_number(self):\n", + " return self.account_number" ] }, { @@ -117,12 +139,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "id": "4f8848b5-05d3-4259-9e24-914537926778", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes hereclass SavingsAccount(BankAccount):\n", + "def _init_(self, balance=0, interest_rate=0.01):\n", + " super()._init_(balance) # heredamos el init de BankAccount\n", + " self.interest_rate = interest_rate\n", + " \n", + "def add_interest(self):\n", + " interest = self.balance * self.interest_rate\n", + " self.balance += interest\n", + " \n", + "def get_interest_rate(self):\n", + " return self.interest_rate" ] }, { @@ -149,16 +181,6 @@ " Interest rate: 0.02" ] }, - { - "cell_type": "code", - "execution_count": null, - "id": "bccc7f6d-d58c-4909-9314-aaf4afc1cd30", - "metadata": {}, - "outputs": [], - "source": [ - "# your code goes here" - ] - }, { "cell_type": "markdown", "id": "a5455a88-a8d1-47a6-86b0-7c70647b4f31", @@ -189,12 +211,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "id": "3c883c6e-3cb8-4043-92d3-12409668a28e", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes hereclass CheckingAccount(BankAccount):\n", + "def _init_(self, balance=0, transaction_fee=0.01):\n", + " super()._init_(balance)\n", + " self.transaction_fee = transaction_fee\n", + " self.transaction_count = 0\n", + "\n", + "def deposit(self, amount):\n", + " super().deposit(amount)\n", + " self.transaction_count += 1\n", + "\n", + "def withdraw(self, amount):\n", + " if amount <= self.balance:\n", + " super().withdraw(amount)\n", + " self.transaction_count += 1\n", + " else:\n", + " print(\"Insufficient balance\")\n", + "\n", + "def deduct_fees(self):\n", + " total_fees = self.balance * self.transaction_fee * self.transaction_count\n", + " if total_fees <= self.balance:\n", + " self.balance -= total_fees\n", + " print(f\"Deducted: {total_fees}\")\n", + " else:\n", + " print(\"Insufficient balance to cover fees\")\n", + " self.transaction_count = 0\n", + "\n", + "def reset_transaction_count(self):\n", + " self.transaction_count = 0\n", + "\n", + "def get_transaction_count(self):\n", + " return self.transaction_count" ] }, { @@ -234,18 +286,48 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "id": "faa5b148-c11b-4be0-b810-de8a7da81451", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes hereclass CheckingAccount(BankAccount):\n", + "def _init_(self, balance=0, transaction_fee=2):\n", + " super()._init_(balance)\n", + " self.transaction_fee = transaction_fee # fee fijo, no porcentaje\n", + " self.transaction_count = 0\n", + "\n", + "def deposit(self, amount):\n", + " super().deposit(amount)\n", + " self.transaction_count += 1\n", + "\n", + "def withdraw(self, amount):\n", + " if amount <= self.balance:\n", + " super().withdraw(amount)\n", + " self.transaction_count += 1\n", + " else:\n", + " print(\"Insufficient balance\")\n", + "\n", + "def deduct_fees(self):\n", + " total_fees = self.transaction_fee * self.transaction_count\n", + " if total_fees <= self.balance:\n", + " self.balance -= total_fees\n", + " print(f\"Transaction fees of ${total_fees} have been deducted from your account balance.\")\n", + " else:\n", + " print(\"Insufficient balance to cover transaction fees.\")\n", + " self.transaction_count = 0\n", + "\n", + "def reset_transaction_count(self):\n", + " self.transaction_count = 0\n", + "\n", + "def get_transaction_count(self):\n", + " return self.transaction_count" ] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -259,7 +341,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.14.0a6" } }, "nbformat": 4,