From 5d34c1012ba4c8d4192ca90c2a58a36a4e57f803 Mon Sep 17 00:00:00 2001 From: annnieglez Date: Mon, 24 Feb 2025 00:51:21 +0100 Subject: [PATCH 1/3] lab done --- lab-python-oop.ipynb | 142 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 129 insertions(+), 13 deletions(-) diff --git a/lab-python-oop.ipynb b/lab-python-oop.ipynb index c13bc58..37232b4 100644 --- a/lab-python-oop.ipynb +++ b/lab-python-oop.ipynb @@ -56,21 +56,65 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "id": "21625526-3fae-4c55-bab5-f91940070681", "metadata": {}, "outputs": [], "source": [ "# your code goes here\n", + "\n", + "class BankAccount:\n", + "\n", + " account_count = 0\n", + " transaction_count = 0\n", + "\n", + " def __init__(self, balance):\n", + " self.balance = balance\n", + " BankAccount.account_count +=1\n", + " self.account_number = BankAccount.account_count\n", + " BankAccount.transaction_count = 0\n", + " self.transaction_count = BankAccount.transaction_count\n", + "\n", + " def deposit(self, amount):\n", + " self.balance += amount\n", + " self.transaction_count =+1\n", + " \n", + " def withdraw(self, amount):\n", + " if amount <= self.balance:\n", + " self.balance -= amount\n", + " self.transaction_count += 1\n", + " else:\n", + " print(\"Insufficient balance.\")\n", + " \n", + " def get_balance(self):\n", + " if self.balance >= 0:\n", + " return self.balance\n", + " \n", + " def get_account_number(self):\n", + " return self.account_number\n", "\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 24, "id": "ee789466-d4cf-4dd8-b742-6863d42c3e5c", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Account 1 balance: 1000\n", + "Account 1 number: 1\n", + "Account 2 balance: 500\n", + "Account 2 number: 2\n", + "Account 1 balance after transactions: 1300\n", + "Insufficient balance.\n", + "Account 2 balance after transactions: 500\n" + ] + } + ], "source": [ "# Testing the BankAccount class\n", "# Creating two instances of the BankAccount class with initial balances of 1000 and 500\n", @@ -117,12 +161,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "id": "4f8848b5-05d3-4259-9e24-914537926778", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "class SavingsAccount(BankAccount):\n", + " def __init__(self, balance,interes_rate = 0.01):\n", + " super().__init__(balance) \n", + " self.interes_rate = interes_rate\n", + "\n", + " def add_interest(self):\n", + " self.balance += self.balance * self.interes_rate\n", + "\n", + " def get_interest_rate(self):\n", + " return self.interes_rate" ] }, { @@ -151,12 +206,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 26, "id": "bccc7f6d-d58c-4909-9314-aaf4afc1cd30", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Current balance: 127.5 and interest rate: 0.02\n" + ] + } + ], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "# Testing the SavingsAccount class\n", + "# Creating a instance of the SavingsAccount class with initial balances of 100 and interest rate of 2%\n", + "saving_account = SavingsAccount(100, 0.02)\n", + "saving_account.deposit(50)\n", + "saving_account.withdraw(25)\n", + "saving_account.add_interest()\n", + "\n", + "print(f\"Current balance: {saving_account.balance} and interest rate: {saving_account.interes_rate}\")" ] }, { @@ -189,12 +261,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 27, "id": "3c883c6e-3cb8-4043-92d3-12409668a28e", "metadata": {}, "outputs": [], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "class CheckingAccount(BankAccount):\n", + " def __init__(self, balance, transaction_fee = 1):\n", + " super().__init__(balance) \n", + " self.transaction_fee = transaction_fee\n", + "\n", + " def deduct_fees(self):\n", + " if self.transaction_fee * self.transaction_count < self.balance:\n", + " self.balance-= self.transaction_fee * self.transaction_count\n", + " print (f\"{self.transaction_fee * self.transaction_count} have been deducted in fees from the account\")\n", + " CheckingAccount.reset_transactions(self) \n", + " else:\n", + " print(\"There is not sufficient funds in the account\")\n", + " \n", + " def reset_transactions(self):\n", + " self.transaction_count = 0\n", + " \n", + " def get_transaction_count(self):\n", + " return self.transaction_count" ] }, { @@ -234,12 +325,37 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 28, "id": "faa5b148-c11b-4be0-b810-de8a7da81451", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4 have been deducted in fees from the account\n", + "Current balance: 546 and transaction count: 0\n", + "4 have been deducted in fees from the account\n", + "Current balance: 667 and transaction count: 0\n" + ] + } + ], "source": [ - "# your code goes here" + "# your code goes here\n", + "\n", + "# Testing the CheckingAccount class\n", + "# Creating a instance of the CheckingAccount class with initial balances of 500 and transaction fee of 2\n", + "\n", + "checking_account = CheckingAccount(500, 2)\n", + "checking_account.deposit(100)\n", + "checking_account.withdraw(50)\n", + "checking_account.deduct_fees()\n", + "print(f\"Current balance: {checking_account.balance} and transaction count: {checking_account.transaction_count}\")\n", + "\n", + "checking_account.deposit(200)\n", + "checking_account.withdraw(75)\n", + "checking_account.deduct_fees()\n", + "print(f\"Current balance: {checking_account.balance} and transaction count: {checking_account.transaction_count}\")" ] } ], From 358fddc16c9131399b15f901d89768a662cfd316 Mon Sep 17 00:00:00 2001 From: annnieglez Date: Mon, 24 Feb 2025 00:55:30 +0100 Subject: [PATCH 2/3] lab done1 --- lab-python-oop.ipynb | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lab-python-oop.ipynb b/lab-python-oop.ipynb index 37232b4..1adc017 100644 --- a/lab-python-oop.ipynb +++ b/lab-python-oop.ipynb @@ -56,7 +56,7 @@ }, { "cell_type": "code", - "execution_count": 23, + "execution_count": null, "id": "21625526-3fae-4c55-bab5-f91940070681", "metadata": {}, "outputs": [], @@ -77,7 +77,7 @@ "\n", " def deposit(self, amount):\n", " self.balance += amount\n", - " self.transaction_count =+1\n", + " self.transaction_count =+ 1\n", " \n", " def withdraw(self, amount):\n", " if amount <= self.balance:\n", @@ -161,7 +161,7 @@ }, { "cell_type": "code", - "execution_count": 25, + "execution_count": 29, "id": "4f8848b5-05d3-4259-9e24-914537926778", "metadata": {}, "outputs": [], @@ -169,15 +169,15 @@ "# your code goes here\n", "\n", "class SavingsAccount(BankAccount):\n", - " def __init__(self, balance,interes_rate = 0.01):\n", + " def __init__(self, balance,interest_rate = 0.01):\n", " super().__init__(balance) \n", - " self.interes_rate = interes_rate\n", + " self.interest_rate = interest_rate\n", "\n", " def add_interest(self):\n", - " self.balance += self.balance * self.interes_rate\n", + " self.balance += self.balance * self.interest_rate\n", "\n", " def get_interest_rate(self):\n", - " return self.interes_rate" + " return self.interest_rate" ] }, { @@ -206,7 +206,7 @@ }, { "cell_type": "code", - "execution_count": 26, + "execution_count": 30, "id": "bccc7f6d-d58c-4909-9314-aaf4afc1cd30", "metadata": {}, "outputs": [ @@ -228,7 +228,7 @@ "saving_account.withdraw(25)\n", "saving_account.add_interest()\n", "\n", - "print(f\"Current balance: {saving_account.balance} and interest rate: {saving_account.interes_rate}\")" + "print(f\"Current balance: {saving_account.balance} and interest rate: {saving_account.interest_rate}\")" ] }, { @@ -261,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 27, + "execution_count": 31, "id": "3c883c6e-3cb8-4043-92d3-12409668a28e", "metadata": {}, "outputs": [], @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 28, + "execution_count": 32, "id": "faa5b148-c11b-4be0-b810-de8a7da81451", "metadata": {}, "outputs": [ From 094a0a9755d9fa28a4ea97d2dfc1e39817156ae3 Mon Sep 17 00:00:00 2001 From: annnieglez Date: Mon, 24 Feb 2025 01:02:52 +0100 Subject: [PATCH 3/3] lab done2 --- lab-python-oop.ipynb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lab-python-oop.ipynb b/lab-python-oop.ipynb index 1adc017..1342496 100644 --- a/lab-python-oop.ipynb +++ b/lab-python-oop.ipynb @@ -261,7 +261,7 @@ }, { "cell_type": "code", - "execution_count": 31, + "execution_count": 35, "id": "3c883c6e-3cb8-4043-92d3-12409668a28e", "metadata": {}, "outputs": [], @@ -277,7 +277,7 @@ " if self.transaction_fee * self.transaction_count < self.balance:\n", " self.balance-= self.transaction_fee * self.transaction_count\n", " print (f\"{self.transaction_fee * self.transaction_count} have been deducted in fees from the account\")\n", - " CheckingAccount.reset_transactions(self) \n", + " self.reset_transactions() \n", " else:\n", " print(\"There is not sufficient funds in the account\")\n", " \n", @@ -325,7 +325,7 @@ }, { "cell_type": "code", - "execution_count": 32, + "execution_count": 36, "id": "faa5b148-c11b-4be0-b810-de8a7da81451", "metadata": {}, "outputs": [