Added Files, Changed Folder Names, AND MUCH MORE!
++ Week 5 Folder ++ Week 5 Homework +- Week 2 Folder Name
This commit is contained in:
parent
ee3222c4ab
commit
4fc499169b
13 changed files with 538 additions and 0 deletions
117
Week-5/06_rounding.ipynb
Normal file
117
Week-5/06_rounding.ipynb
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"# Rounding with Function Calls"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"These exercises give you practice calling functions in Python."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Question 1.** Using the function `round`, round the number 1.23456789 to the nearest integer. Give the result the name `rounded`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rounded = ...\n",
|
||||
"rounded"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Question 2.** Round 1.23456789 to the nearest *thousandth* (.001).\n",
|
||||
"\n",
|
||||
"*Hint:* Running `round?` in a code cell will show you Python's documentation for the `round` function."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 5,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"less_rounded = ...\n",
|
||||
"less_rounded"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"Suppose you're counting all the small donations made to a political candidate. The donations were:\n",
|
||||
"\n",
|
||||
"* 32.25\n",
|
||||
"* 15.00\n",
|
||||
"* 24.45\n",
|
||||
"\n",
|
||||
"You need to report the total rounded to the nearest dollar.\n",
|
||||
"\n",
|
||||
"**Question 3.** First you decide to round *each donation* individually and then add up those 3 rounded amounts. Compute that."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 7,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"sum_of_rounded_amounts = ...\n",
|
||||
"sum_of_rounded_amounts"
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
"**Question 4.** You suspect this method doesn't work quite right. To check, you decide to try a different method: Adding up the donations, and then rounding the total. Compute that."
|
||||
]
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 9,
|
||||
"metadata": {},
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"rounded_sum = ...\n",
|
||||
"rounded_sum"
|
||||
]
|
||||
}
|
||||
],
|
||||
"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.8.3"
|
||||
}
|
||||
},
|
||||
"nbformat": 4,
|
||||
"nbformat_minor": 1
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue