Add video and streamline content
This commit is contained in:
parent
6e68175252
commit
6d2c7aeaa1
3 changed files with 419 additions and 687 deletions
|
|
@ -4,8 +4,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"\n",
|
||||
"# Chapter 5: Bits & Numbers"
|
||||
"# Chapter 5: Numbers & Bits"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -19,7 +18,9 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Read [Chapter 5](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/05_numbers_00_lecture.ipynb) of the book. Then, work through the exercises below. The `...` indicate where you need to fill in your answers. You should not need to create any additional code cells."
|
||||
"The exercises below assume that you have read [Chapter 5](https://nbviewer.jupyter.org/github/webartifex/intro-to-python/blob/master/05_numbers_00_lecture.ipynb) in the book.\n",
|
||||
"\n",
|
||||
"The `...`'s in the code cells indicate where you need to fill in code snippets. The number of `...`'s within a code cell give you a rough idea of how many lines of code are needed to solve the task. You should not need to create any additional code cells for your final solution. However, you may want to use temporary code cells to try out some ideas."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -80,7 +81,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
" "
|
||||
" < your answer >"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -94,7 +95,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
" "
|
||||
" < your answer >"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -110,7 +111,7 @@
|
|||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
" "
|
||||
" < your answer >"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -238,7 +239,7 @@
|
|||
"\n",
|
||||
"Enable **duck typing** by allowing the function to be called with various numeric types as the arguments, in particular, `quantity` may be a non-integer as well: Use an appropriate **abstract base class** from the [numbers](https://docs.python.org/3/library/numbers.html) module in the [standard library](https://docs.python.org/3/library/index.html) to verify the arguments' types and also that they are both positive!\n",
|
||||
"\n",
|
||||
"It is considered a *best practice* to only round towards the *end* of the calculations."
|
||||
"Hint: It is considered a *best practice* to only round towards the *end* of the calculations."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
@ -256,8 +257,43 @@
|
|||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"def discounted_price(...):\n",
|
||||
" ..."
|
||||
"def discounted_price(unit_price, quantity):\n",
|
||||
" \"\"\"Calculate the price of a line item in an order.\n",
|
||||
"\n",
|
||||
" Args:\n",
|
||||
" unit_price (numbers.Real): price of an ordered item; must be positive\n",
|
||||
" quantity (numbers.Real): number of items ordered; must be positive\n",
|
||||
"\n",
|
||||
" Returns:\n",
|
||||
" line_item_price (decimal.Decimal): precision of 2 decimals\n",
|
||||
" \"\"\"\n",
|
||||
" # Basic input validation.\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
"\n",
|
||||
" # Calculate the final price if only\n",
|
||||
" # the first discount scheme is applied.\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
"\n",
|
||||
" # Calculate the final price if only\n",
|
||||
" # the second discount scheme is applied.\n",
|
||||
" # \"One in every five\" means we need to figure out\n",
|
||||
" # how many full groups of five are contained.\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
" ...\n",
|
||||
"\n",
|
||||
" # Choose the better option for the customer.\n",
|
||||
" ...\n",
|
||||
" # Round correctly for pricing purposes.\n",
|
||||
" return ..."
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue