Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab-pyhton-oop #51

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
206 changes: 198 additions & 8 deletions lab-python-oop.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 1,
"id": "21625526-3fae-4c55-bab5-f91940070681",
"metadata": {},
"outputs": [],
Expand All @@ -67,10 +67,62 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "ee789466-d4cf-4dd8-b742-6863d42c3e5c",
"execution_count": 2,
"id": "8ccf704e",
"metadata": {},
"outputs": [],
"source": [
"class BankAccount:\n",
" account_count = 0\n",
"\n",
" def __init__ ( self, balance):\n",
" BankAccount.account_count +- 1\n",
" self.balance = balance\n",
" self.account_number = BankAccount.account_count\n",
"\n",
" \n",
" def deposit(self, amount):\n",
" if amount > 0:\n",
" self.balance += amount\n",
" else:\n",
" print(\"Valor no permitido\")\n",
"\n",
" def withdraw(self, amount):\n",
" if amount > 0:\n",
" if amount > self.balance:\n",
" print (\"Saldo insuficiente\")\n",
" else:\n",
" self.balance -= amount\n",
" else:\n",
" print(\"Valor no permitido\")\n",
"\n",
" def get_balance(self):\n",
" return (f\"El balance de la cuenta es: {self.balance}\") \n",
" \n",
" def get_account_number(self):\n",
" return (f\"El numero de cuenta es: {self.account_count}\") "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "ee789466-d4cf-4dd8-b742-6863d42c3e5c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Account 1 balance: El balance de la cuenta es: 1000\n",
"Account 1 number: El numero de cuenta es: <__main__.BankAccount object at 0x0000025240A60B90>\n",
"Account 2 balance: El balance de la cuenta es: 500\n",
"Account 2 number: El numero de cuenta es: <__main__.BankAccount object at 0x0000025240A61C90>\n",
"Account 1 balance after transactions: El balance de la cuenta es: 1300\n",
"Saldo insuficiente\n",
"Account 2 balance after transactions: El balance de la cuenta es: 500\n"
]
}
],
"source": [
"# Testing the BankAccount class\n",
"# Creating two instances of the BankAccount class with initial balances of 1000 and 500\n",
Expand Down Expand Up @@ -117,14 +169,65 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"id": "4f8848b5-05d3-4259-9e24-914537926778",
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "555de020",
"metadata": {},
"outputs": [],
"source": [
"class SavingsAccount(BankAccount):\n",
" \n",
" def __init__ (self, balance, interest_rate=0.01):\n",
" super().__init__(balance)\n",
" self.interest_rate = interest_rate\n",
" \n",
" def add_interest(self, interest_rate):\n",
" self.balance += (self.balance * interest_rate)\n",
"\n",
" def get_interest_rate(self):\n",
" return (f\"El ratio de interes de la cuenta {self} es: {self.interest_rate}\")\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "530da754",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"El balance de account1 es El balance de la cuenta es: 126.25\n",
"La account1 tiene una tasa de interes anual de El ratio de interes de la cuenta <__main__.SavingsAccount object at 0x0000025240A24C90> es: 0.02\n"
]
}
],
"source": [
"account1 = SavingsAccount(100, 0.02)\n",
"\n",
"account1.deposit (50) \n",
"account1.withdraw (25) \n",
"\n",
"\n",
"\n",
"account1.add_interest (0.01)\n",
"account1.get_interest_rate()\n",
"\n",
"\n",
"print (f\"El balance de account1 es {account1.get_balance()}\")\n",
"print (f\"La account1 tiene una tasa de interes anual de {account1.get_interest_rate()}\")"
]
},
{
"cell_type": "markdown",
"id": "d2c84bdb-e7d1-491d-9b0e-194288702c02",
Expand All @@ -151,7 +254,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"id": "bccc7f6d-d58c-4909-9314-aaf4afc1cd30",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -189,14 +292,55 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 8,
"id": "3c883c6e-3cb8-4043-92d3-12409668a28e",
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "bfbbac94",
"metadata": {},
"outputs": [],
"source": [
"class CheckingAccount(BankAccount):\n",
"\n",
" def __init__(self, balance, transaction_fee = 1, transaction_count = 0):\n",
" super().__init__(balance)\n",
" self.transaction_fee = transaction_fee\n",
" self.transaction_count = transaction_count\n",
" \n",
" def deposit(self, amount):\n",
" super().deposit(amount)\n",
" if amount > 0:\n",
" self.transaction_count += 1\n",
" \n",
" \n",
" def withdraw(self, amount):\n",
" super().withdraw(amount)\n",
" if amount > 0:\n",
" self.transaction_count += 1\n",
"\n",
" def deduct_fees(self):\n",
" comisiones = self.transaction_fee * self.transaction_count\n",
" if comisiones <= self.balance:\n",
" self.balance -= comisiones\n",
" self.reset_transactions()\n",
" return (f\"Las comisiones de este periodo ascienden a: {comisiones}\")\n",
" else:\n",
" return (f\"El saldo es insuficiente\")\n",
"\n",
" def reset_transactions(self):\n",
" self.transaction_count = 0\n",
"\n",
" def get_transaction_count(self):\n",
" return (f\"El numero actual de transacciones de la cuenta {self} es de: {self.transaction_count}\")"
]
},
{
"cell_type": "markdown",
"id": "8217ec46-3eae-4a7c-9c7c-d4a87aac7e6d",
Expand Down Expand Up @@ -234,13 +378,59 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 27,
"id": "faa5b148-c11b-4be0-b810-de8a7da81451",
"metadata": {},
"outputs": [],
"source": [
"# your code goes here"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "5eb2c302",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"El balance de la cuenta es: 546\n",
"El numero actual de transacciones de la cuenta <__main__.CheckingAccount object at 0x000001FCA3B50ED0> es de: 0\n",
"El balance de la cuenta es: 667\n",
"El numero actual de transacciones de la cuenta <__main__.CheckingAccount object at 0x000001FCA3B50ED0> es de: 0\n"
]
}
],
"source": [
"account1 = CheckingAccount(500, 2)\n",
"\n",
"account1.deposit (100) \n",
"account1.withdraw (50) \n",
"\n",
"account1.deduct_fees()\n",
"\n",
"print (f\"{account1.get_balance()}\")\n",
"print (f\"{account1.get_transaction_count()}\")\n",
"\n",
"account1.deposit(200)\n",
"account1.withdraw(75)\n",
"\n",
"account1.deduct_fees()\n",
" \n",
"print (f\"{account1.get_balance()}\")\n",
"print (f\"{account1.get_transaction_count()}\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3bdead95",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -259,7 +449,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down