{ "cells": [ { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "e501e33a42462e5b2334918173054fd7", "grade": false, "grade_id": "preamble", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "# Using Python, Numpy, Jupyter, and Syzygy\n", "## Objective\n", "To practice using key tools that we'll need to use during this course.\n", "## Instructions\n", "Before you turn this problem in, make sure everything runs as expected. First, restart the kernel (in the menubar, select Kernel → Restart) and then run all cells (in the menubar, select Cell → Run All).\n", "\n", "Make sure you fill in any place that says YOUR CODE HERE or \"YOUR ANSWER HERE\", as well as your name, username (the prefix to your @university.ext e-mail), and student ID number in the cell below" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "Name = \"First M. Last\"\n", "email_user_name = \"username\"\n", "ID_number = 1234567" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "590f618fd681610de44e99b0dc9d15f3", "grade": false, "grade_id": "problem_description", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## Problem Statement\n", "Write a Python function to compute the final mark for a student in this class. \n", "- **Input**: a list of assignment grades, a final exam grade, and a number of pages of extra credit that have been provided.\n", "- **Output**: the final mark. \n", "Grading Scheme:\n", "- Assignment grades are replaced by the final exam grade if the final exam grade is higher.\n", "- The final mark (without extra credit) is \n", "\n", "$$ \n", "\\text{total mark} = 0.2(\\text{final exam grade}) + 0.8(\\text{mean of assignment grades after replacements})\n", "$$\n", "- Extra credit counts by replacing a set percentage (up to 40%) of your final mark with a 100%. The percentage of your final mark that is replaced is given by the below formula. No more than 1200 pages of extra credit problems can be done.\n", "\n", "$$\n", "\\text{percent extra credit} = \\frac{\\text{number of pages of extra credit}}{1200} \\cdot 40\n", "$$" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "2a70f583c850597a313ba79e422e769d", "grade": false, "grade_id": "one_student_grade", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "\n", "def total_mark_xc(assignments, exam, extra_credit_pages=0):\n", " \"\"\"Computes the final mark for one student in CHEM 3PA3 in 2021\n", "\n", " Parameters\n", " ----------\n", " assignments : array_like\n", " assignment grades.\n", " exam : scalar\n", " the grade on the final project/exam.\n", " extra_credit_pages : scalar, optional\n", " the number of extra credit pages. (default is 0)\n", "\n", " Returns\n", " -------\n", " total_mark_xc : scalar\n", " The final mark in the course, computed according to the syllabus.\n", " \"\"\"\n", "\n", " # YOUR CODE HERE\n", " raise NotImplementedError()" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "f4972f3bab164206f1d7cccba8e6affc", "grade": true, "grade_id": "one_student_test", "locked": true, "points": 100, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "# It's good to always test to make sure your code is right.\n", "np.testing.assert_almost_equal(total_mark_xc([100, 100, 100, 100], 0), 80)\n", "np.testing.assert_almost_equal(total_mark_xc([0, 0], 100, 0), 100)\n", "np.testing.assert_almost_equal(total_mark_xc([0, 0], 0, 1200), 40)\n" ] }, { "cell_type": "markdown", "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "markdown", "checksum": "81298eab1b102259d89d85f2afdbdbda", "grade": false, "grade_id": "multiple_students", "locked": true, "schema_version": 3, "solution": false, "task": false } }, "source": [ "## Extend to Multiple students\n", "It is easy to use Numpy to extend this analysis to multiple students. Suppose that you had assignments, finals, and extra credit for more than one student. Rewrite your function so it works for that case too. This extra credit problem is worth 15 \"points\", so you can make a 115 on this assignment.\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "nbgrader": { "cell_type": "code", "checksum": "934fc89a8cc67a07f893bf2a08e45a24", "grade": false, "grade_id": "mult_student_code", "locked": false, "schema_version": 3, "solution": true, "task": false } }, "outputs": [], "source": [ "import numpy as np\n", "\n", "\n", "def total_mark_xc_mult(assignments, exam, extra_credit_pages):\n", " \"\"\"Computes the final mark for multiple students CHEM 3PA3 in 2021\n", "\n", " Parameters\n", " ----------\n", " assignments : array_like\n", " assignment grades; number-of-students by number-of-assignments\n", " exam : array_like\n", " the grade on the final project/exam for each student.\n", " extra_credit_pages : array_like\n", " the number of extra credit pages for each student\n", "\n", " Returns\n", " -------the\n", " total_mark_xc : array_like\n", " The final mark in the course for all students, computed according to the syllabus.\n", " \"\"\"\n", "\n", " # YOUR CODE HERE\n", " raise NotImplementedError()\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "deletable": false, "editable": false, "nbgrader": { "cell_type": "code", "checksum": "1f2d29f657b32c62aa8c8b519d7c78cd", "grade": true, "grade_id": "mult_student_tests", "locked": true, "points": 15, "schema_version": 3, "solution": false, "task": false } }, "outputs": [], "source": [ "assignments = np.array([[100, 100, 100, 100], [0, 0, 0, 0], [0, 0, 0, 0]])\n", "exam = np.array([0, 100, 0])\n", "extra_credit_pages = np.array([0, 0, 1200])\n", "np.testing.assert_almost_equal(\n", " total_mark_xc_mult(assignments, exam, extra_credit_pages), [80.0, 100.0, 40.0]\n", ")" ] } ], "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": 4 }