From 4fc499169ba63b651b26c2c430e9e885182e1f31 Mon Sep 17 00:00:00 2001 From: cdez Date: Wed, 28 Sep 2022 09:23:14 -0700 Subject: [PATCH] Added Files, Changed Folder Names, AND MUCH MORE! ++ Week 5 Folder ++ Week 5 Homework +- Week 2 Folder Name --- ...01 Pride and Prejudice(1)-checkpoint.ipynb | 0 ... How Paper Boxes are made-checkpoint.ipynb | 0 .../01 Pride and Prejudice(1).ipynb | 0 {Week 2 => Week-2}/14111835.omcsettings.txt | 0 {Week 2 => Week-2}/64212-0.txt | 0 ...Analysis of How Paper Boxes are made.ipynb | 0 {Week 2 => Week-2}/pg64317.txt | 0 Week-5/01_basic_names.ipynb | 73 ++++++++++ Week-5/02_confusing_names.ipynb | 75 +++++++++++ Week-5/03_naming_errors.ipynb | 79 +++++++++++ Week-5/04_basic_arithmetic.ipynb | 126 ++++++++++++++++++ Week-5/05_maxmin.ipynb | 68 ++++++++++ Week-5/06_rounding.ipynb | 117 ++++++++++++++++ 13 files changed, 538 insertions(+) rename {Week 2 => Week-2}/.ipynb_checkpoints/01 Pride and Prejudice(1)-checkpoint.ipynb (100%) rename {Week 2 => Week-2}/.ipynb_checkpoints/Homework 1 - Literary Analysis of How Paper Boxes are made-checkpoint.ipynb (100%) rename {Week 2 => Week-2}/01 Pride and Prejudice(1).ipynb (100%) rename {Week 2 => Week-2}/14111835.omcsettings.txt (100%) rename {Week 2 => Week-2}/64212-0.txt (100%) rename {Week 2 => Week-2}/Homework 1 - Literary Analysis of How Paper Boxes are made.ipynb (100%) rename {Week 2 => Week-2}/pg64317.txt (100%) create mode 100644 Week-5/01_basic_names.ipynb create mode 100644 Week-5/02_confusing_names.ipynb create mode 100644 Week-5/03_naming_errors.ipynb create mode 100644 Week-5/04_basic_arithmetic.ipynb create mode 100644 Week-5/05_maxmin.ipynb create mode 100644 Week-5/06_rounding.ipynb diff --git a/Week 2/.ipynb_checkpoints/01 Pride and Prejudice(1)-checkpoint.ipynb b/Week-2/.ipynb_checkpoints/01 Pride and Prejudice(1)-checkpoint.ipynb similarity index 100% rename from Week 2/.ipynb_checkpoints/01 Pride and Prejudice(1)-checkpoint.ipynb rename to Week-2/.ipynb_checkpoints/01 Pride and Prejudice(1)-checkpoint.ipynb diff --git a/Week 2/.ipynb_checkpoints/Homework 1 - Literary Analysis of How Paper Boxes are made-checkpoint.ipynb b/Week-2/.ipynb_checkpoints/Homework 1 - Literary Analysis of How Paper Boxes are made-checkpoint.ipynb similarity index 100% rename from Week 2/.ipynb_checkpoints/Homework 1 - Literary Analysis of How Paper Boxes are made-checkpoint.ipynb rename to Week-2/.ipynb_checkpoints/Homework 1 - Literary Analysis of How Paper Boxes are made-checkpoint.ipynb diff --git a/Week 2/01 Pride and Prejudice(1).ipynb b/Week-2/01 Pride and Prejudice(1).ipynb similarity index 100% rename from Week 2/01 Pride and Prejudice(1).ipynb rename to Week-2/01 Pride and Prejudice(1).ipynb diff --git a/Week 2/14111835.omcsettings.txt b/Week-2/14111835.omcsettings.txt similarity index 100% rename from Week 2/14111835.omcsettings.txt rename to Week-2/14111835.omcsettings.txt diff --git a/Week 2/64212-0.txt b/Week-2/64212-0.txt similarity index 100% rename from Week 2/64212-0.txt rename to Week-2/64212-0.txt diff --git a/Week 2/Homework 1 - Literary Analysis of How Paper Boxes are made.ipynb b/Week-2/Homework 1 - Literary Analysis of How Paper Boxes are made.ipynb similarity index 100% rename from Week 2/Homework 1 - Literary Analysis of How Paper Boxes are made.ipynb rename to Week-2/Homework 1 - Literary Analysis of How Paper Boxes are made.ipynb diff --git a/Week 2/pg64317.txt b/Week-2/pg64317.txt similarity index 100% rename from Week 2/pg64317.txt rename to Week-2/pg64317.txt diff --git a/Week-5/01_basic_names.ipynb b/Week-5/01_basic_names.ipynb new file mode 100644 index 0000000..ccfc8cc --- /dev/null +++ b/Week-5/01_basic_names.ipynb @@ -0,0 +1,73 @@ +{ + "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": 7, + "metadata": {}, + "outputs": [], + "source": [ + "roughly_e = ...\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": 2, + "metadata": {}, + "outputs": [], + "source": [ + "n = ...\n", + "also_roughly_e = ...\n", + "also_roughly_e" + ] + } + ], + "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 +} diff --git a/Week-5/02_confusing_names.ipynb b/Week-5/02_confusing_names.ipynb new file mode 100644 index 0000000..97cbf8c --- /dev/null +++ b/Week-5/02_confusing_names.ipynb @@ -0,0 +1,75 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Confusing Names" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Question 1.** Some physicists and computer scientists were partying late one night, and they decided to figure out roughly how much beer it would take to cover the whole surface of the Sun 3 meters deep. They found the following facts:\n", + "\n", + "1. The average density (mass per volume) of the Sun is 1410 $\\texttt{kg}/\\texttt{m}^3$.\n", + "2. The Sun weighs $1.989 \\times 10^{30} \\texttt{kg}$.\n", + "3. The Sun's volume is its weight divided by its density.\n", + "4. The Sun is roughly a sphere.\n", + "5. The radius of a sphere is $(\\texttt{volume} \\times \\frac{3}{4 \\times \\pi})^{1/3}$\n", + "6. $\\pi$ is roughly 3.14159.\n", + "7. The surface area of a sphere is $4 \\times \\pi \\times \\texttt{radius}^2$.\n", + "\n", + "They wrote code in the next cell to compute the answer. But the next morning, they couldn't figure out what their code did, because none of the names made sense. To help clarify their code, replace the names used in the next cell with appropriate names chosen from the following list:\n", + "\n", + "* `required_beer_volume`\n", + "* `sun_radius`\n", + "* `sun_volume`\n", + "* `sun_surface_area`\n", + "* `sun_density`\n", + "* `pi`\n", + "* `sun_weight`" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "a = 1410\n", + "b = 1.989 * 10**30\n", + "c = 3\n", + "d = b / a\n", + "e = 3.14159\n", + "f = (d * 3/(4*e))**(1/3)\n", + "g = 4 * e * f**2\n", + "h = c * g" + ] + } + ], + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Week-5/03_naming_errors.ipynb b/Week-5/03_naming_errors.ipynb new file mode 100644 index 0000000..42ceda9 --- /dev/null +++ b/Week-5/03_naming_errors.ipynb @@ -0,0 +1,79 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Errors in Naming" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Question 1.** When you run the following cell, Python will produce an slightly-cryptic error message. Explain in the text cell below, in your own words, what's wrong with the code. (Remember, double-click the cell to edit it, and then click the Run button when you're done.)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "4 = 2 + 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Write your answer here, replacing this text.*" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Question 2.** When you run the following cell, Python will produce an slightly-cryptic error message. **Fix the error,** and then **explain below** in your own words what was wrong with the code." + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "two = 2\n", + "four = two plus two" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Write your answer here, replacing this text.*" + ] + } + ], + "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.7.1" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Week-5/04_basic_arithmetic.ipynb b/Week-5/04_basic_arithmetic.ipynb new file mode 100644 index 0000000..7673465 --- /dev/null +++ b/Week-5/04_basic_arithmetic.ipynb @@ -0,0 +1,126 @@ +{ + "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 +} diff --git a/Week-5/05_maxmin.ipynb b/Week-5/05_maxmin.ipynb new file mode 100644 index 0000000..a34bbbd --- /dev/null +++ b/Week-5/05_maxmin.ipynb @@ -0,0 +1,68 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The Middle" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Suppose that Yulin, another INF110 student, is tasked with writing code to find the middle of three distinct numbers named `a`, `b`, and `c`. (By “middle” we mean the value that is neither the maximum nor the minimum.) For example, given the values 4, 2, and 7, the code should give back 4.\n", + "\n", + "Yulin has a moment of inspired thought and rapidly types the following into her Jupyter notebook:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "collapsed": true + }, + "outputs": [], + "source": [ + "a + b + c - max(a, b, c) + min(a, b, c)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Is her code correct? Why or why not? If not, make a *simple* change to the cell above to fix it.\n", + "\n", + "*Hint:* Running the cell will produce an error because we haven't defined `a`, `b`, and `c`, but you're free to make any changes you want to test your ideas. (When you submit, just indicate which cell is your final answer.)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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 +} diff --git a/Week-5/06_rounding.ipynb b/Week-5/06_rounding.ipynb new file mode 100644 index 0000000..7e0e010 --- /dev/null +++ b/Week-5/06_rounding.ipynb @@ -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 +}