126 lines
3.2 KiB
Text
126 lines
3.2 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Basic Arithmetic in Python\n",
|
|
"This set of exercises gives you practice writing basic arithmetic expressions in Python."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 1.** In the next cell, write a Python expression equivalent to this math expression:\n",
|
|
"\n",
|
|
"$$1 - \\frac{2^2}{2^{20}}$$\n",
|
|
"\n",
|
|
"The value of the expression is around 0.999996. After you have something that works, try to improve your solution by using only as many parentheses as you need. You can add a cell under your initial answer to show your work."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"..."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 2.** Try to predict the value of the expression in the next cell. Before you run the cell, write your prediction in the cell below it."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 9,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"1 - 2 ** 3 / 4 + 5 * 6"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {
|
|
"collapsed": true
|
|
},
|
|
"outputs": [],
|
|
"source": [
|
|
"# Your prediction here:\n",
|
|
"..."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 3.** Try to predict whether the value of the expression below is larger or smaller than the value of the expression in the previous question. You can use the next cell to record your answer. Then run the cell to see what happens. If you were wrong, figure out why, and include that in your written answer."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 10,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"1 - 2 ** (3 / 4 + 5 * 6)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"*Write your answer here, replacing this text.*"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 4.** A famous fact in mathematics is that\n",
|
|
"\n",
|
|
"$$(1 - \\frac{1}{n})^{-n}$$\n",
|
|
"\n",
|
|
"gets very close to the number $e$, which is roughly $2.718$, when $n$ is large. Verify that it gets closer to $e$ as $n$ gets larger by writing this expression in Python and trying different values for $n$.\n",
|
|
"\n",
|
|
"*Hint:* If you write several expressions in a cell, only the last will be printed. If you want to see the values of several copies of the expression at once, put `print(...)` around them. Alternatively, you can use separate cells for each expression."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 8,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"..."
|
|
]
|
|
}
|
|
],
|
|
"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
|
|
}
|