forked from Pierian-Data/Complete-Python-3-Bootcamp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0f14403
commit 5cedc1d
Showing
4 changed files
with
780 additions
and
0 deletions.
There are no files selected for viewing
187 changes: 187 additions & 0 deletions
187
05-Object Oriented Programming/.ipynb_checkpoints/04-OOP Challenge-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Object Oriented Programming Challenge\n", | ||
"\n", | ||
"For this challenge, create a bank account class that has two attributes:\n", | ||
"\n", | ||
"* owner\n", | ||
"* balance\n", | ||
"\n", | ||
"and two methods:\n", | ||
"\n", | ||
"* deposit\n", | ||
"* withdraw\n", | ||
"\n", | ||
"As an added requirement, withdrawals may not exceed the available balance.\n", | ||
"\n", | ||
"Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class Account:\n", | ||
" pass" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 1. Instantiate the class\n", | ||
"acct1 = Account('Jose',100)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Account owner: Jose\n", | ||
"Account balance: $100\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 2. Print the object\n", | ||
"print(acct1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'Jose'" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# 3. Show the account owner attribute\n", | ||
"acct1.owner" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"100" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# 4. Show the account balance attribute\n", | ||
"acct1.balance" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Deposit Accepted\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 5. Make a series of deposits and withdrawals\n", | ||
"acct1.deposit(50)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Withdrawal Accepted\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"acct1.withdraw(75)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Funds Unavailable!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 6. Make a withdrawal that exceeds the available balance\n", | ||
"acct1.withdraw(500)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Good job!" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
203 changes: 203 additions & 0 deletions
203
...ject Oriented Programming/.ipynb_checkpoints/05-OOP Challenge - Solution-checkpoint.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,203 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# Object Oriented Programming Challenge - Solution\n", | ||
"\n", | ||
"For this challenge, create a bank account class that has two attributes:\n", | ||
"\n", | ||
"* owner\n", | ||
"* balance\n", | ||
"\n", | ||
"and two methods:\n", | ||
"\n", | ||
"* deposit\n", | ||
"* withdraw\n", | ||
"\n", | ||
"As an added requirement, withdrawals may not exceed the available balance.\n", | ||
"\n", | ||
"Instantiate your class, make several deposits and withdrawals, and test to make sure the account can't be overdrawn." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 1, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"class Account:\n", | ||
" def __init__(self,owner,balance=0):\n", | ||
" self.owner = owner\n", | ||
" self.balance = balance\n", | ||
" \n", | ||
" def __str__(self):\n", | ||
" return f'Account owner: {self.owner}\\nAccount balance: ${self.balance}'\n", | ||
" \n", | ||
" def deposit(self,dep_amt):\n", | ||
" self.balance += dep_amt\n", | ||
" print('Deposit Accepted')\n", | ||
" \n", | ||
" def withdraw(self,wd_amt):\n", | ||
" if self.balance >= wd_amt:\n", | ||
" self.balance -= wd_amt\n", | ||
" print('Withdrawal Accepted')\n", | ||
" else:\n", | ||
" print('Funds Unavailable!')" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 2, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"# 1. Instantiate the class\n", | ||
"acct1 = Account('Jose',100)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 3, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Account owner: Jose\n", | ||
"Account balance: $100\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 2. Print the object\n", | ||
"print(acct1)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"'Jose'" | ||
] | ||
}, | ||
"execution_count": 4, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# 3. Show the account owner attribute\n", | ||
"acct1.owner" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"data": { | ||
"text/plain": [ | ||
"100" | ||
] | ||
}, | ||
"execution_count": 5, | ||
"metadata": {}, | ||
"output_type": "execute_result" | ||
} | ||
], | ||
"source": [ | ||
"# 4. Show the account balance attribute\n", | ||
"acct1.balance" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 6, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Deposit Accepted\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 5. Make a series of deposits and withdrawals\n", | ||
"acct1.deposit(50)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 7, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Withdrawal Accepted\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"acct1.withdraw(75)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": 8, | ||
"metadata": {}, | ||
"outputs": [ | ||
{ | ||
"name": "stdout", | ||
"output_type": "stream", | ||
"text": [ | ||
"Funds Unavailable!\n" | ||
] | ||
} | ||
], | ||
"source": [ | ||
"# 6. Make a withdrawal that exceeds the available balance\n", | ||
"acct1.withdraw(500)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"## Good job!" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.6.2" | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 2 | ||
} |
Oops, something went wrong.