-- IPYNB Checkpoints ++ Git Ignore File for IPYNB Checkpoints +- Week 5 Homework Files
95 lines
2.2 KiB
Text
95 lines
2.2 KiB
Text
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Names in Python"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 1.** 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. Use this fact to compute an approximation to $e$, called `roughly_e`. Your approximation should be correct to at least 5 decimal places."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"2.7182820533299275"
|
|
]
|
|
},
|
|
"execution_count": 4,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"roughly_e = (1 + (1/99999999999))**99999999999\n",
|
|
"roughly_e"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"**Question 2.** In the previous question, you might have noticed that you had to type in the value of $n$ twice when you tried different values (once as `1/n` and once as `**n`). You might have even accidentally used 2 different values.\n",
|
|
"\n",
|
|
"Redo the code in the cell below, giving your estimate of $e$ the name `also_roughly_e`. Instead of writing the value of $n$ twice, give it the name `n` in your Python code, and then use that name in your expression for `also_roughly_e`."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/plain": [
|
|
"2.7182820533299275"
|
|
]
|
|
},
|
|
"execution_count": 6,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"n = 99999999999\n",
|
|
"also_roughly_e = (1+(1/n))**n\n",
|
|
"also_roughly_e"
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"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.9.12"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 1
|
|
}
|