{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "*This notebook contains material for CBE 20258 Numerical and Statistical Analysis taught at the University of Notre Dame. (c) Professors Alexander Dowling, Ryan McClarren, and Yamil Colón. This collection of notebooks [cbe-xx258](https://ndcbe.github.io/cbe-xx258) is available [on Github](https://github.com/ndcbe/cbe-xx258).*\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [1.0 Python Primer](https://ndcbe.github.io/cbe-xx258/01.00-Python-Primer.html) | [Contents](toc.html) | [1.2 Learning Python Basics](https://ndcbe.github.io/cbe-xx258/01.02-Variables.html) >

\"Open

\"Download\"" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 1, "link": "[1.1 Welcome to Jupyter Notebooks and Vocareum](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1-Welcome-to-Jupyter-Notebooks-and-Vocareum)", "section": "1.1 Welcome to Jupyter Notebooks and Vocareum" } }, "source": [ "# 1.1 Welcome to Jupyter Notebooks and Vocareum" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.1 Quick Python Introduction](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1-Quick-Python-Introduction)", "section": "1.1.1 Quick Python Introduction" } }, "source": [ "## 1.1.1 Quick Python Introduction" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "### 1.1.1.1 Variables" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "In Python, variables do not need to be declared before they are used. In other words, Python automatically decided on the correct variable type (integer, float, etc.) You can simply define a new variable using `x = 5`. This is just like MATLAB." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "

\n", "Home Activity: In the cell below, assign the value of 5 to the variable x. Then type Shift+Enter to execute the line.\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "We can see the value of the variable using the built-in `print` function. For example, to print the value of `x`, we would use `print(x)`." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "
\n", "Home Activity: Print the value of x. Type Shift+Enter to execute the cell. (We'll stop reminding you to do this moving forward.)\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "source": [ "
\n", "Home Activity: Now change the value of x to 8 and execute the cell.\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbpages": { "level": 3, "link": "[1.1.1.1 Variables](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.1-Variables)", "section": "1.1.1.1 Variables" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.2 Execution Order](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.2-Execution-Order)", "section": "1.1.1.2 Execution Order" } }, "source": [ "### 1.1.1.2 Execution Order\n", "\n", "**Note**: When using Jupyter notebooks, it is very important to know that the cells can be executed out of order\n", "(intentionally or not). The state of the environment (e.g., values of variables, imports, etc.) is defined by the execution\n", "order." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.2 Execution Order](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.2-Execution-Order)", "section": "1.1.1.2 Execution Order" } }, "source": [ "
\n", "Home Activity: To see this concept, rerun the cell above with the print statement.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.1.2 Execution Order](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.1.2-Execution-Order)", "section": "1.1.1.2 Execution Order" } }, "source": [ "You should see that the value `8` is now printed. This may seem problematic if you are used to programming in environments where the state is linked to the order of the commands as *written*, not as *executed*.\n", "\n", "**Again, notice that the state of the environment is determined by the execution order.**\n", "Note also that the square brackets to the left of the cell show the order that cells were executed. If you scroll to the top, you should see that the code cells show an execution order of `[1]` , `[2]` , `[5]` , and `[4]`, indicating the actual execution order.\n", "\n", "There are some useful menu commands at the top of the Jupyter notebook to help with these problems and make sure you\n", "retain the execution order as expected.\n", "\n", "Some important commands to remember:\n", "* You can clear the current state with the menu item `Kernel | Restart & Clear Output`\n", "* It is often useful to clear the state using the menu command just described, and then execute all the lines above the currently selected cell using `Cell | Run All Above` .\n", "* You can clear all the state and re-run the entire notebook using `Kernel | Restart & Run All`." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "source": [ "## 1.1.2 Vocareum Autograder\n" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "source": [ "
\n", "Note: The autograder is NOT supported on Colab. All of the autograder tests and solutions have been stripped out of these notebooks.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "source": [ "We will use the autograder in Vocareum for homework assignments, which gives you instant feedback on your work. The autograder is confirmed to allow for unlimited submissions. You just need to wait 5 minutes between submissions.\n", "\n", "It is very important carefully read the assignment instructions. The autograder is simply executing logical checks behind the scenes. For example, if the assignment instructions say to store your final answer in the variable `final_ans` but you instead write `my_ans`, the autograder will mark it as wrong.\n", "\n", "### Our First Autograded Submission\n", "\n", "We want to store the **first seven elements** of the Fibonaci sequence in the list `fib`. Below is an answer with a few mistakes:" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbgrader": { "grade": false, "grade_id": "cell-d1b0242a12e0275b", "locked": false, "schema_version": 1, "solution": true }, "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "outputs": [], "source": [ "# YOUR SOLUTION HERE\n", "\n", "fibs = [0, -1, 1, 2, 4, 5, 9, 13]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbgrader": { "grade": true, "grade_id": "sequence-length", "locked": true, "points": 0.3, "schema_version": 1, "solution": false }, "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": true, "nbgrader": { "grade": true, "grade_id": "sequent-correct", "locked": true, "points": 0.7, "schema_version": 1, "solution": false }, "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "source": [ "
\n", "Home Activity: Submit this solution and look at the feedback from the autograder.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.2 Vocareum Autograder](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.2-Vocareum-Autograder)", "section": "1.1.2 Vocareum Autograder" } }, "source": [ "
\n", "Home Activity: Fix the mistakes. You are done when all of the grading tests pass.\n", "
" ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 2, "link": "[1.1.3 Gradescope](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.3-Gradescope)", "section": "1.1.3 Gradescope" } }, "source": [ "## 1.1.3 Gradescope\n", "\n", "The autograde in Vocareum is nice for (near) instant feedback. But we'll also use Gradescope throughout the semester to collect assignments that require \"pencil and paper\" analysis or written discussion." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.3.1 Handwritten Work](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.3.1-Handwritten-Work)", "section": "1.1.3.1 Handwritten Work" } }, "source": [ "### 1.1.3.1 Handwritten Work\n", "\n", "We'll occassionally ask you to submit handwritten work (e.g., mathematical models, pseudocode) via Gradescope. Here are the instructions:\n", "1. Scan/photograph your work and convert to a single PDF. “Scanbot” (Android & iOS), “CamScanner” (Android & iOS) and “Scannable” (iOS) are great phone apps with free versions. There are also document scanners in the library. See the syllabus for more information.\n", "2. Upload the single PDF to Gradescope.\n", "3. Mark the sections as requested in Gradescope." ] }, { "cell_type": "markdown", "metadata": { "nbpages": { "level": 3, "link": "[1.1.3.2 Notebooks](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.3.2-Notebooks)", "section": "1.1.3.2 Notebooks" } }, "source": [ "### 1.1.3.2 Notebooks" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "nbpages": { "level": 3, "link": "[1.1.3.2 Notebooks](https://ndcbe.github.io/cbe-xx258/01.01-Jupyter-Notebooks.html#1.1.3.2-Notebooks)", "section": "1.1.3.2 Notebooks" } }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "< [1.0 Python Primer](https://ndcbe.github.io/cbe-xx258/01.00-Python-Primer.html) | [Contents](toc.html) | [1.2 Learning Python Basics](https://ndcbe.github.io/cbe-xx258/01.02-Variables.html) >

\"Open

\"Download\"" ] } ], "metadata": { "celltoolbar": "Create Assignment", "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.3" } }, "nbformat": 4, "nbformat_minor": 2 }