diff --git a/Exams/Final/Final - Copy.ipynb b/Exams/Final/Final - Copy.ipynb new file mode 100644 index 0000000..6bf9cfa --- /dev/null +++ b/Exams/Final/Final - Copy.ipynb @@ -0,0 +1,892 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Final Exam" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Recall the drawing system from lecture 18:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "class Canvas:\n", + " def __init__(self, width, height):\n", + " self.width = width\n", + " self.height = height\n", + " self.data = [[' '] * width for i in range(height)]\n", + "\n", + " def set_pixel(self, row, col, char='*'):\n", + " self.data[row][col] = char\n", + "\n", + " def get_pixel(self, row, col):\n", + " return self.data[row][col]\n", + " \n", + " def h_line(self, x, y, w, **kargs):\n", + " for i in range(x,x+w):\n", + " self.set_pixel(i,y, **kargs)\n", + "\n", + " def v_line(self, x, y, h, **kargs):\n", + " for i in range(y,y+h):\n", + " self.set_pixel(x,i, **kargs)\n", + " \n", + " def line(self, x1, y1, x2, y2, **kargs):\n", + " slope = 0\n", + " if x2 != x1:\n", + " slope = (y2-y1) / (x2-x1)\n", + " if (slope > 0 or slope < 0) and y1 != y2 and x1 != x2:\n", + " if x1 < x2:\n", + " for x in range(x1,x2):\n", + " y= y1 + int((x - x1) * slope)\n", + " self.set_pixel(x,y, **kargs)\n", + " elif x2 < x1:\n", + " for x in range(x1,x2, -1):\n", + " y=y2 + int((x-x2) * slope)\n", + " self.set_pixel(x,y, **kargs)\n", + " elif y2 == y1:\n", + " if x1 > x2:\n", + " self.h_line(x2, y2, x1-x2, **kargs)\n", + " elif x2 > x1:\n", + " self.h_line(x2, y2, x2-x1, **kargs)\n", + " elif x2 == x1:\n", + " if y1 > y2:\n", + " self.v_line(x2, y2, y1-y2, **kargs)\n", + " elif y2 > y2:\n", + " self.v_line(x2, y2, y2-y1, **kargs)\n", + " \n", + " \n", + " def display(self):\n", + " print(\"\\n\".join([\"\".join(row) for row in self.data]))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "class Shape:\n", + " def __init__(self, name=\"\", **kwargs):\n", + " self.name=name\n", + " self.kwargs=kwargs\n", + " \n", + " def paint(self, canvas): pass\n", + "\n", + "class Rectangle(Shape):\n", + " def __init__(self, x, y, w, h, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.w = w\n", + " self.h = h\n", + "\n", + " def paint(self, canvas):\n", + " canvas.h_line(self.x, self.y, self.w, **self.kwargs)\n", + " canvas.h_line(self.x, self.y + self.h, self.w, **self.kwargs)\n", + " canvas.v_line(self.x, self.y, self.h, **self.kwargs)\n", + " canvas.v_line(self.x + self.w, self.y, self.h, **self.kwargs)\n", + "\n", + "class Square(Rectangle):\n", + " def __init__(self, x, y, size, **kwargs):\n", + " Rectangle.__init__(self, x, y, size, size, **kwargs)\n", + "\n", + "class Line(Shape):\n", + " def __init__(self, x1, y1, x2, y2, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x1=x1\n", + " self.y1=y1\n", + " self.x2=x2\n", + " self.y2=y2\n", + " \n", + " def paint(self, canvas):\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2)\n", + " \n", + "class CompoundShape(Shape):\n", + " def __init__(self, shapes):\n", + " self.shapes = shapes\n", + "\n", + " def paint(self, canvas):\n", + " for s in self.shapes:\n", + " s.paint(canvas)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class RasterDrawing:\n", + " def __init__(self):\n", + " self.shapes=dict()\n", + " self.shape_names=list()\n", + " \n", + " def add_shape(self,shape):\n", + " if shape.name == \"\":\n", + " shape.name = self.assign_name()\n", + " \n", + " self.shapes[shape.name]=shape\n", + " self.shape_names.append(shape.name)\n", + " \n", + " def paint(self,canvas):\n", + " for shape_name in self.shape_names:\n", + " self.shapes[shape_name].paint(canvas)\n", + " \n", + " def assign_name(self):\n", + " name_base=\"shape\"\n", + " name = name_base+\"_0\"\n", + " \n", + " i=1\n", + " while name in self.shapes:\n", + " name = name_base+\"_\"+str(i)\n", + " \n", + " return name\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Add `Point` and `Triangle` classes and test them." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "class Point(Shape):\n", + " def __init__(self, x, y, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + "\n", + " def paint(self, canvas):\n", + " canvas.set_pixel(self.x, self.y, **self.kwargs)\n", + "\n", + "class Triangle(Shape):\n", + " def __init__(self, x1, y1, x2, y2, x3, y3, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x1 = x1\n", + " self.y1 = y1\n", + " self.x2 = x2\n", + " self.y2 = y2\n", + " self.x3 = x3\n", + " self.y3 = y3\n", + "\n", + " def paint(self, canvas):\n", + " canvas.line(self.x1, self.y1, self.x2, self.y2, **self.kwargs)\n", + " canvas.line(self.x2, self.y2, self.x3, self.y3, **self.kwargs)\n", + " canvas.line(self.x3, self.y3, self.x1, self.y1, **self.kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " ++++++++++++++++++++++++++++++ \n", + " + + \n", + " + + \n", + " . + + \n", + " . . + + \n", + " . . + + \n", + " . . + \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . . \n", + " . \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "c1=Canvas(50,25)\n", + "#s1=Square(5,5,20,char=\"^\")\n", + "#s1.paint(c1)\n", + "p1=Point(20,20,char=\".\")\n", + "p1.paint(c1)\n", + "t1=Triangle(5,5,10,20,20,5, char=\".\")\n", + "t1.paint(c1)\n", + "t2=Triangle(2,5,8,25,2,35, char=\"+\")\n", + "t2.paint(c1)\n", + "c1.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Add an `Arc` class that is instantiated with a center location, two axis lengths, and starting and ending angles. If start and end are not specified or are the same angle, the `Arc` instance should draw an oval. If in addition the two axes are the same, the `Arc` instance should draw a circle. Create `Oval` and `Circle` classes that inherit from `Arc`. Test everything." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import math\n", + "class Arc(Shape):\n", + " def __init__(self, x, y, rx, ry, start=None, stop=None, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.rx = rx\n", + " self.ry = ry\n", + " self.start = start\n", + " self.stop = stop\n", + "\n", + " def paint(self, canvas):\n", + " if self.start != None and self.stop != None and self.start != self.stop:\n", + " dt = (self.stop - self.start)/360\n", + " for theta in np.arange(self.start, self.stop, dt):\n", + " x = int(self.rx * math.cos(theta) + self.x)\n", + " y = int(self.ry * math.sin(theta) + self.y)\n", + " canvas.set_pixel(x,y,**self.kwargs)\n", + " else:\n", + " dt = 2*math.pi/360\n", + " for theta in np.arange(0, 2*math.pi, dt):\n", + " x = int(self.rx * math.cos(theta) + self.x)\n", + " y = int(self.ry * math.sin(theta) + self.y)\n", + " canvas.set_pixel(x,y,**self.kwargs)\n", + "class Oval(Arc):\n", + " def __init__(self, x, y, rx, ry, **kwargs):\n", + " Arc.__init__(self, x, y, rx, ry, start=None, stop=None, **kwargs)\n", + "class Circle(Arc):\n", + " def __init__(self, x, y, r, **kwargs):\n", + " Arc.__init__(self, x, y, r, r, start=None, stop=None, **kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " 111111111111 222222222222 \n", + " 11 11 22 22 \n", + " 11 11 22 22 \n", + " 1 1 2 2 \n", + " 1 1 2 2 \n", + " 11 2 22 \n", + " 1 2 2 \n", + " 11 22 22 \n", + " 11 22 22 \n", + " 111111 222222222222 \n", + " 1 2 \n", + " \n", + " \n", + " \n", + " \n", + " 333333333333 444444444444 \n", + " 33 33 44 44 \n", + " 33 33 44 44 \n", + " 3 3 4 4 \n", + " 3 3 4 4 \n", + " 3 33 4 44 \n", + " 3 3 4 4 \n", + " 33 33 44 44 \n", + " 33 33 44 44 \n", + " 333333333333 444444444444 \n", + " 3 4 \n", + " \n", + " \n", + " \n", + " \n", + " 555555 666666 \n", + " 5 5 6 6 \n", + " 5 5 6 6 \n", + " 5 5 6 6 \n", + " 5 5 6 6 \n", + " 5 55 6 66 \n", + " 5 5 6 6 \n", + " 5 5 6 6 \n", + " 5 5 6 6 \n", + " 555555 666666 \n", + " 5 6 \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "c1=Canvas(70,50)\n", + "# normal arc\n", + "# draws (part of) an oval but looks like a circle\n", + "a1=Arc(10,15,5,10,0,1.5*math.pi, char=\"1\")\n", + "a1.paint(c1)\n", + "# arc w/ same start and end\n", + "a2=Arc(10,40,5,10,math.pi,math.pi, char=\"2\")\n", + "a2.paint(c1)\n", + "# arc w/o start and end\n", + "# draws an oval but looks like a circle\n", + "a3=Arc(25,15,5,10,char=\"3\")\n", + "a3.paint(c1)\n", + "o1=Oval(25,40,5,10,char=\"4\")\n", + "o1.paint(c1)\n", + "# arc with same rx and ry\n", + "# draws a circle but looks like an oval\n", + "a4=Arc(40,15,5,5,char=\"5\")\n", + "a4.paint(c1)\n", + "cr1=Circle(40,40,5,char=\"6\")\n", + "cr1.paint(c1)\n", + "c1.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Use your classes to create a `RasterDrawing` that draws a happy face." + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 111111111111 \n", + " 111 111 \n", + " 11 11 \n", + " 11 11 \n", + " 11 11 \n", + " 1 444444 1 \n", + " 1 44 1 \n", + " 11 44 11 \n", + " 1 4 22222222 1 \n", + "11 4 2 2 11 \n", + "1 44 2 22 1 \n", + "1 4 22222222 1 \n", + "1 4 2 1 \n", + "1 4 1 \n", + "1 4 1 \n", + "1 4 11\n", + "1 4 1 \n", + "1 4 1 \n", + "1 4 33333333 1 \n", + "1 44 3 3 1 \n", + "11 4 3 33 11 \n", + " 1 4 33333333 1 \n", + " 11 44 3 11 \n", + " 1 44 1 \n", + " 1 44444 1 \n", + " 11 11 \n", + " 11 11 \n", + " 11 11 \n", + " 111 111 \n", + " 111111111111 \n", + " 1 \n" + ] + } + ], + "source": [ + "c1=Canvas(31,31)\n", + "rd=RasterDrawing()\n", + "\n", + "rd.add_shape(Circle(15,15,15,char=\"1\",name=\"head\"))\n", + "rd.add_shape(Oval(10,18,2,4,char=\"2\",name=\"left eye\"))\n", + "rd.add_shape(Oval(20,18,2,4,char=\"3\",name=\"right eye\"))\n", + "rd.add_shape(Arc(15,15,10,10,math.pi,2*math.pi,char=\"4\",name=\"mouth\"))\n", + "\n", + "rd.paint(c1)\n", + "\n", + "c1.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Add to the `Shape` base class a `__str__()` method. Overwrite the method in each shape to generate a string of the python code necessary to reinstantiate the object. For example, for a rectangle originally instantiated using `Square(5,5,20,char=\"^\")`, `__str__()` should return the string `'Square(5,5,20,char=\"^\")'`.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [], + "source": [ + "class Shape:\n", + " def __init__(self, name=\"\", **kwargs):\n", + " self.name=name\n", + " self.kwargs=kwargs\n", + " \n", + " def paint(self, canvas): pass\n", + " \n", + " def __str__(self): pass\n", + "\n", + "class Rectangle(Shape):\n", + " def __init__(self, x, y, w, h, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.w = w\n", + " self.h = h\n", + "\n", + " def paint(self, canvas):\n", + " canvas.h_line(self.x, self.y, self.w, **self.kwargs)\n", + " canvas.h_line(self.x, self.y + self.h, self.w, **self.kwargs)\n", + " canvas.v_line(self.x, self.y, self.h, **self.kwargs)\n", + " canvas.v_line(self.x + self.w, self.y, self.h, **self.kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Rectangle({},{},{},{},'.format(self.x,self.y,self.w,self.h)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Square(Rectangle):\n", + " def __init__(self, x, y, size, **kwargs):\n", + " Rectangle.__init__(self, x, y, size, size, **kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Square({},{},{},'.format(self.x,self.y,self.w)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Line(Shape):\n", + " def __init__(self, x1, y1, x2, y2, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x1=x1\n", + " self.y1=y1\n", + " self.x2=x2\n", + " self.y2=y2\n", + " \n", + " def paint(self, canvas):\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2)\n", + " \n", + " def __str__(self):\n", + " string = 'Line({},{},{},{},'.format(self.x1,self.y1,self.x2,self.y2)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + " \n", + "class CompoundShape(Shape):\n", + " def __init__(self, shapes):\n", + " self.shapes = shapes\n", + "\n", + " def paint(self, canvas):\n", + " for s in self.shapes:\n", + " s.paint(canvas)\n", + " \n", + " def __str__(self):\n", + " string = 'CompoundShape(['\n", + " for shape in self.shapes:\n", + " string += str(shape) + ','\n", + " string = string[:-1] + '])'\n", + " return string\n", + "\n", + "class Point(Shape):\n", + " def __init__(self, x, y, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + "\n", + " def paint(self, canvas):\n", + " canvas.set_pixel(self.x, self.y, **self.kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Point({},{},'.format(self.x,self.y)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Triangle(Shape):\n", + " def __init__(self, x1, y1, x2, y2, x3, y3, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x1 = x1\n", + " self.y1 = y1\n", + " self.x2 = x2\n", + " self.y2 = y2\n", + " self.x3 = x3\n", + " self.y3 = y3\n", + "\n", + " def paint(self, canvas):\n", + " canvas.line(self.x1, self.y1, self.x2, self.y2, **self.kwargs)\n", + " canvas.line(self.x2, self.y2, self.x3, self.y3, **self.kwargs)\n", + " canvas.line(self.x3, self.y3, self.x1, self.y1, **self.kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Triangle({},{},{},{},{},{},'.format(self.x1,self.y1,self.x2,self.y2,self.x3,self.y3)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Arc(Shape):\n", + " def __init__(self, x, y, rx, ry, start=None, stop=None, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.rx = rx\n", + " self.ry = ry\n", + " self.start = start\n", + " self.stop = stop\n", + "\n", + " def paint(self, canvas):\n", + " if self.start != None and self.stop != None and self.start != self.stop:\n", + " dt = (self.stop - self.start)/360\n", + " for theta in np.arange(self.start, self.stop, dt):\n", + " x = int(self.rx * math.cos(theta) + self.x)\n", + " y = int(self.ry * math.sin(theta) + self.y)\n", + " canvas.set_pixel(x,y,**self.kwargs)\n", + " else:\n", + " dt = 2*math.pi/360\n", + " for theta in np.arange(0, 2*math.pi, dt):\n", + " x = int(self.rx * math.cos(theta) + self.x)\n", + " y = int(self.ry * math.sin(theta) + self.y)\n", + " canvas.set_pixel(x,y,**self.kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Arc({},{},{},{},{},{},'.format(self.x,self.y,self.rx,self.ry,self.start,self.stop)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Oval(Arc):\n", + " def __init__(self, x, y, rx, ry, **kwargs):\n", + " Arc.__init__(self, x, y, rx, ry, start=None, stop=None, **kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Oval({},{},{},{},'.format(self.x,self.y,self.rx,self.ry)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string\n", + "\n", + "class Circle(Arc):\n", + " def __init__(self, x, y, r, **kwargs):\n", + " Arc.__init__(self, x, y, r, r, start=None, stop=None, **kwargs)\n", + " \n", + " def __str__(self):\n", + " string = 'Circle({},{},{},'.format(self.x,self.y,self.rx)\n", + " for key in self.kwargs.keys():\n", + " if isinstance(self.kwargs[key],str):\n", + " string += key + \"='\" + self.kwargs[key] + \"',\"\n", + " else:\n", + " string += key + '=' + self.kwargs[key] + ','\n", + " if self.name != '':\n", + " string += \"name='\" + self.name + \"')\"\n", + " else:\n", + " string = string[:-1] + \")\"\n", + " return string" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Rectangle(4,3,2,1,char='1',name='r1')\n", + "Square(3,2,1,char='2')\n", + "Line(4,3,2,1,char='3')\n", + "CompoundShape([Rectangle(4,3,2,1,char='1',name='r1'),Square(3,2,1,char='2'),Line(4,3,2,1,char='3')])\n", + "Point(2,1,char='4')\n", + "Triangle(6,5,4,3,2,1,char='5')\n", + "Arc(6,5,4,3,0,3.141592653589793,char='6')\n", + "Oval(4,3,2,1,char='7')\n", + "Circle(3,2,1,char='8')\n" + ] + } + ], + "source": [ + "r1=Rectangle(4,3,2,1,char='1',name='r1')\n", + "s1=Square(3,2,1,char='2')\n", + "l1=Line(4,3,2,1,char='3')\n", + "compound=CompoundShape([r1,s1,l1])\n", + "p1=Point(2,1,char='4')\n", + "t1=Triangle(6,5,4,3,2,1,char='5')\n", + "a1=Arc(6,5,4,3,0,math.pi,char='6')\n", + "o1=Oval(4,3,2,1,char='7')\n", + "c1=Circle(3,2,1,char='8')\n", + "print(str(r1))\n", + "print(str(s1))\n", + "print(str(l1))\n", + "print(str(compound))\n", + "print(str(p1))\n", + "print(str(t1))\n", + "print(str(a1))\n", + "print(str(o1))\n", + "print(str(c1))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Add to `RasterDrawing` two functions, `save(filename)` and `load(filename)`. The save function writes the `__str__()` of all of the shapes in the drawing to a file (one shape per line). The load function, reads the file, and instantiates each object using the python `eval(expression)` function, and adds each shape to the drawing, thereby recreating a \"saved\" raster drawing. Use this functionality to save and load your happy face.\n", + "\n", + " `eval` takes a string that contains a fragment of a python code and executes it. Consider the following examples: " + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello\n" + ] + } + ], + "source": [ + "eval(\"print('Hello')\")" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n" + ] + } + ], + "source": [ + "x = eval('1+2')\n", + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "class RasterDrawing:\n", + " def __init__(self):\n", + " self.shapes=dict()\n", + " self.shape_names=list()\n", + " \n", + " def add_shape(self,shape):\n", + " if shape.name == \"\":\n", + " shape.name = self.assign_name()\n", + " \n", + " self.shapes[shape.name]=shape\n", + " self.shape_names.append(shape.name)\n", + " \n", + " def paint(self,canvas):\n", + " for shape_name in self.shape_names:\n", + " self.shapes[shape_name].paint(canvas)\n", + " \n", + " def assign_name(self):\n", + " name_base=\"shape\"\n", + " name = name_base+\"_0\"\n", + " \n", + " i=1\n", + " while name in self.shapes:\n", + " name = name_base+\"_\"+str(i)\n", + " \n", + " return name\n", + " \n", + " def save(self,filename):\n", + " sf = open(filename, 'w')\n", + " string = \"\"\n", + " for shape_name in self.shape_names:\n", + " string += str(self.shapes[shape_name])+'\\n'\n", + " sf.write(string[:-1])\n", + " sf.close()\n", + " \n", + " def load(self,filename):\n", + " sf = open(filename, 'r')\n", + " for line in sf:\n", + " self.add_shape(eval(line))\n", + " sf.close()" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 111111111111 \n", + " 111 111 \n", + " 11 11 \n", + " 11 11 \n", + " 11 11 \n", + " 1 444444 1 \n", + " 1 44 1 \n", + " 11 44 11 \n", + " 1 4 22222222 1 \n", + "11 4 2 2 11 \n", + "1 44 2 22 1 \n", + "1 4 22222222 1 \n", + "1 4 2 1 \n", + "1 4 1 \n", + "1 4 1 \n", + "1 4 11\n", + "1 4 1 \n", + "1 4 1 \n", + "1 4 33333333 1 \n", + "1 44 3 3 1 \n", + "11 4 3 33 11 \n", + " 1 4 33333333 1 \n", + " 11 44 3 11 \n", + " 1 44 1 \n", + " 1 44444 1 \n", + " 11 11 \n", + " 11 11 \n", + " 11 11 \n", + " 111 111 \n", + " 111111111111 \n", + " 1 \n" + ] + } + ], + "source": [ + "rd=RasterDrawing()\n", + "\n", + "rd.add_shape(Circle(15,15,15,char=\"1\",name=\"head\"))\n", + "rd.add_shape(Oval(10,18,2,4,char=\"2\",name=\"left eye\"))\n", + "rd.add_shape(Oval(20,18,2,4,char=\"3\",name=\"right eye\"))\n", + "rd.add_shape(Arc(15,15,10,10,math.pi,2*math.pi,char=\"4\",name=\"mouth\"))\n", + "\n", + "rd.save(\"savedRasterDrawing\")\n", + "del rd\n", + "rd = RasterDrawing()\n", + "rd.load(\"savedRasterDrawing\")\n", + "\n", + "c1=Canvas(31,31)\n", + "\n", + "rd.paint(c1)\n", + "\n", + "c1.display()" + ] + }, + { + "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.7.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Exams/Mid-term/Exam-checkpoint.ipynb b/Exams/Mid-term/Exam-checkpoint.ipynb new file mode 100644 index 0000000..f6e3ec9 --- /dev/null +++ b/Exams/Mid-term/Exam-checkpoint.ipynb @@ -0,0 +1,457 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Mid-term Exam\n", + "\n", + "Add cells to this notebook as you need for you solutions and your test of your solutions." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Write a function `first_alphabetically(lst)` that takes a list `lst` of strings and returns the string that is alphabetically first. For example, calling your function with the list of states:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "states=['Mississippi', 'Maryland', 'Delaware', 'Connecticut', 'Virginia', 'Utah', 'Kansas',\n", + " 'Wyoming', 'Indiana', 'Louisiana', 'Missouri', 'Illinois', 'Minnesota', 'Vermont', \n", + " 'New Mexico', 'North Dakota', 'Wisconsin', 'Tennessee', 'New York', 'Oklahoma', \n", + " 'Colorado', 'Pennsylvania', 'West Virginia', 'Alabama', 'Montana', 'Texas', \n", + " 'Washington', 'Michigan', 'New Hampshire', 'Arkansas', 'Hawaii', 'Iowa', \n", + " 'Idaho', 'Kentucky', 'Ohio', 'Nebraska', 'Alaska', 'Oregon', 'South Dakota', \n", + " 'New Jersey', 'Florida', 'Georgia', 'Rhode Island', 'Arizona', 'Maine', \n", + " 'South Carolina', 'California', 'Nevada', 'Massachusetts', 'North Carolina']" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "should return the string `\"Alabama\"`. Note that you can compare strings:" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "print(\"A\">\"B\")\n", + "print(\"B\">\"A\")\n", + "print(\"A\">\"a\")\n", + "print(\"bca\">\"bbc\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Make sure your implementation isn't case sensitive. Do not use python's built-in `sort` or any other sort function you find." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Alabama\n" + ] + } + ], + "source": [ + "def first_alphabetically(lst):\n", + " # return min(lst)\n", + " first = lst[0]\n", + " for state in lst:\n", + " if first.upper() > state.upper():\n", + " first = state\n", + " return first\n", + "\n", + "\n", + "print(first_alphabetically(states))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Write a function `arg_first_alphabetically(lst)`, which does the same thing as in exercise 1 but returns the index of the first string alphabetically." + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23\n" + ] + } + ], + "source": [ + "def arg_first_alphabetically(lst):\n", + " # return lst.index(min(lst))\n", + " \n", + " first = lst[0]\n", + " first_index = 0\n", + " for i in range(1, len(lst)):\n", + " if first.upper() > lst[i].upper():\n", + " first = lst[i]\n", + " first_index = i\n", + " return first_index\n", + "\n", + "\n", + "print(arg_first_alphabetically(states))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Use your result in question 2 to implement a function `arg_sort_alphabetically(lst)` that returns a list that is alphabetically sorted. Sorting can be accomplished by successively applying the function in question 1 and removing the first element alphabetically. You can remove an element from a list using `pop()`. Do not use python's built-in `sort` or any other sort function you find. " + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alabama',\n", + " 'Alaska',\n", + " 'Arizona',\n", + " 'Arkansas',\n", + " 'California',\n", + " 'Colorado',\n", + " 'Connecticut',\n", + " 'Delaware',\n", + " 'Florida',\n", + " 'Georgia',\n", + " 'Hawaii',\n", + " 'Idaho',\n", + " 'Illinois',\n", + " 'Indiana',\n", + " 'Iowa',\n", + " 'Kansas',\n", + " 'Kentucky',\n", + " 'Louisiana',\n", + " 'Maine',\n", + " 'Maryland',\n", + " 'Massachusetts',\n", + " 'Michigan',\n", + " 'Minnesota',\n", + " 'Mississippi',\n", + " 'Missouri',\n", + " 'Montana',\n", + " 'Nebraska',\n", + " 'Nevada',\n", + " 'New Hampshire',\n", + " 'New Jersey',\n", + " 'New Mexico',\n", + " 'New York',\n", + " 'North Carolina',\n", + " 'North Dakota',\n", + " 'Ohio',\n", + " 'Oklahoma',\n", + " 'Oregon',\n", + " 'Pennsylvania',\n", + " 'Rhode Island',\n", + " 'South Carolina',\n", + " 'South Dakota',\n", + " 'Tennessee',\n", + " 'Texas',\n", + " 'Utah',\n", + " 'Vermont',\n", + " 'Virginia',\n", + " 'Washington',\n", + " 'West Virginia',\n", + " 'Wisconsin',\n", + " 'Wyoming']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def arg_sort_alphabetically(lst):\n", + " return [lst.pop(arg_first_alphabetically(lst)) for i in range(len(lst))]\n", + "\n", + "\n", + "arg_sort_alphabetically(states)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Implement a function `outer_product` that takes two one-dimensional lists of numbers and returns the two-dimensional outer product matrix defined as:\n", + "\n", + "\\begin{equation*}\n", + "\\begin{pmatrix} x_1\\\\x_2\\\\ \\vdots \\\\x_m \\end{pmatrix} \\begin{pmatrix} y_1&y_2& \\dots &y_n\\end{pmatrix} =\n", + "\\begin{pmatrix}\n", + "x_1y_1 & x_1y_2 & \\dots & x_1y_n\\\\\n", + "x_2y_1 & x_2y_2 & \\dots & x_2y_n\\\\\n", + "\\vdots & \\vdots & \\ddots & \\vdots \\\\\n", + "x_my_1 & x_my_2 & \\dots & x_my_n\n", + "\\end{pmatrix}\n", + "\\end{equation*}\n", + "\n", + "In other words the elements of matrix C which is the outer product of A and B are $c_{ij} = a_i b_j$." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 7, 8]\n", + "[12, 14, 16]\n", + "[18, 21, 24]\n", + "[24, 28, 32]\n", + "[30, 35, 40]\n" + ] + } + ], + "source": [ + "def outer_product(lst1, lst2):\n", + " lst3 = [[0 for i in range(len(lst2))] for j in range(len(lst1))]\n", + " for i in range(len(lst1)):\n", + " for j in range(len(lst2)):\n", + " lst3[i][j] = lst1[i]*lst2[j]\n", + " return lst3\n", + "\n", + "tl1 = [1, 2, 3, 4, 5]\n", + "tl2 = [6, 7, 8]\n", + "op = outer_product(tl1, tl2)\n", + "for l in op:\n", + " print(l)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Implement a function `cumulative_sum(lst)` that takes a list of numbers and returns a list of same size where the element `i` is the sum of the elements `0` to `i` of the input list. For example given `[1,2,3]`, you should return [1,3,6]." + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5]\n", + "[1, 3, 6, 10, 15]\n" + ] + } + ], + "source": [ + "def cumulative_sum(lst):\n", + " for i in range(1, len(lst)):\n", + " lst[i] += lst[i-1]\n", + " return lst\n", + "\n", + "\n", + "tl = list(range(1,6))\n", + "print(tl)\n", + "print(cumulative_sum(tl))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Imagine you have a normal distributed random variable `x`. For example `x` can be grades on this exam. Using the normal distribution generator and histogram functions from lecture (provided below) and `cumulative_sum` from previous question to compute what is the value of `x_{90}` in $\\sigma$ such that 90% of the values $x$ are below `x_{90}`. In other words:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "$$\n", + "\\int_{-\\infty}^{x_{90}} N(x;\\mu=0,\\sigma=1) dx = 0.9\n", + "$$" + ] + }, + { + "cell_type": "code", + "execution_count": 68, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "import math\n", + "\n", + "\n", + "# all code in this block from lectures #\n", + "\n", + "\n", + "def arange(x_min, x_max, steps=10):\n", + " step_size = (x_max - x_min) /steps\n", + " x = x_min\n", + " out = list()\n", + " for i in range(steps):\n", + " out.append(x)\n", + " x += step_size\n", + " return out\n", + "\n", + "\n", + "def generate_normal(N,m=0,s=1):\n", + " out = list() \n", + " \n", + " while len(out)=bin_edges[i] and d= x_90*sigma][0])\n", + " percentage = 100 * cumulative_sum(hist[0][:first_index_above_x_90_sigma])[-1]/len(x)\n", + " print(\" N:\", N)\n", + " print(\" sigma:\", sigma)\n", + " print(\" x_90: {:1.3f}\".format(x_90)) # I expect ~ 1.3\n", + " print(\" x_90*s: {:1.3f}\".format(x_90 * sigma))\n", + " print(\"% < x_90*s: {:3.1f}%\".format(percentage))\n", + " print()" + ] + } + ], + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Exams/Mid-term/Exam.ipynb b/Exams/Mid-term/Exam.ipynb index 5200376..420876e 100644 --- a/Exams/Mid-term/Exam.ipynb +++ b/Exams/Mid-term/Exam.ipynb @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -43,9 +43,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n" + ] + } + ], "source": [ "print(\"A\">\"B\")\n", "print(\"B\">\"A\")\n", @@ -60,6 +71,32 @@ "Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find." ] }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Alabama\n" + ] + } + ], + "source": [ + "def first_alphabetically(lst):\n", + " # return min(lst)\n", + " first = lst[0]\n", + " for state in lst:\n", + " if first.upper() > state.upper():\n", + " first = state\n", + " return first\n", + "\n", + "\n", + "print(first_alphabetically(states))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -67,6 +104,35 @@ "2. Write a function `arg_first_alphabetically(lst)`, which does the same thing as in exercise 1 but returns the index of the first string alphabetically." ] }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "23\n" + ] + } + ], + "source": [ + "def arg_first_alphabetically(lst):\n", + " # return lst.index(min(lst))\n", + " \n", + " first = lst[0]\n", + " first_index = 0\n", + " for i in range(1, len(lst)):\n", + " if first.upper() > lst[i].upper():\n", + " first = lst[i]\n", + " first_index = i\n", + " return first_index\n", + "\n", + "\n", + "print(arg_first_alphabetically(states))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -74,6 +140,79 @@ "3. Use your result in question 2 to implement a function `arg_sort_alphabetically(lst)` that returns a list that is alphabetically sorted. Sorting can be accomplished by successively applying the function in question 1 and removing the first element alphabetically. You can remove an element from a list using `pop()`. Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find." ] }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "['Alabama',\n", + " 'Alaska',\n", + " 'Arizona',\n", + " 'Arkansas',\n", + " 'California',\n", + " 'Colorado',\n", + " 'Connecticut',\n", + " 'Delaware',\n", + " 'Florida',\n", + " 'Georgia',\n", + " 'Hawaii',\n", + " 'Idaho',\n", + " 'Illinois',\n", + " 'Indiana',\n", + " 'Iowa',\n", + " 'Kansas',\n", + " 'Kentucky',\n", + " 'Louisiana',\n", + " 'Maine',\n", + " 'Maryland',\n", + " 'Massachusetts',\n", + " 'Michigan',\n", + " 'Minnesota',\n", + " 'Mississippi',\n", + " 'Missouri',\n", + " 'Montana',\n", + " 'Nebraska',\n", + " 'Nevada',\n", + " 'New Hampshire',\n", + " 'New Jersey',\n", + " 'New Mexico',\n", + " 'New York',\n", + " 'North Carolina',\n", + " 'North Dakota',\n", + " 'Ohio',\n", + " 'Oklahoma',\n", + " 'Oregon',\n", + " 'Pennsylvania',\n", + " 'Rhode Island',\n", + " 'South Carolina',\n", + " 'South Dakota',\n", + " 'Tennessee',\n", + " 'Texas',\n", + " 'Utah',\n", + " 'Vermont',\n", + " 'Virginia',\n", + " 'Washington',\n", + " 'West Virginia',\n", + " 'Wisconsin',\n", + " 'Wyoming']" + ] + }, + "execution_count": 19, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "def arg_sort_alphabetically(lst):\n", + " return [lst.pop(arg_first_alphabetically(lst)) for i in range(len(lst))]\n", + "\n", + "\n", + "arg_sort_alphabetically(states)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -93,6 +232,38 @@ "In other words the elements of matrix C which is the outer product of A and B are $c_{ij} = a_i b_j$." ] }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[6, 7, 8]\n", + "[12, 14, 16]\n", + "[18, 21, 24]\n", + "[24, 28, 32]\n", + "[30, 35, 40]\n" + ] + } + ], + "source": [ + "def outer_product(lst1, lst2):\n", + " lst3 = [[0 for i in range(len(lst2))] for j in range(len(lst1))]\n", + " for i in range(len(lst1)):\n", + " for j in range(len(lst2)):\n", + " lst3[i][j] = lst1[i]*lst2[j]\n", + " return lst3\n", + "\n", + "tl1 = [1, 2, 3, 4, 5]\n", + "tl2 = [6, 7, 8]\n", + "op = outer_product(tl1, tl2)\n", + "for l in op:\n", + " print(l)" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -100,6 +271,32 @@ "5. Implement a function `cumulative_sum(lst)` that takes a list of numbers and returns a list of same size where the element `i` is the sum of the elements `0` to `i` of the input list. For example given `[1,2,3]`, you should return [1,3,6]." ] }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5]\n", + "[1, 3, 6, 10, 15]\n" + ] + } + ], + "source": [ + "def cumulative_sum(lst):\n", + " for i in range(1, len(lst)):\n", + " lst[i] += lst[i-1]\n", + " return lst\n", + "\n", + "\n", + "tl = list(range(1,6))\n", + "print(tl)\n", + "print(cumulative_sum(tl))" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -118,10 +315,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, "outputs": [], "source": [ +<<<<<<< HEAD + "import random\n", + "import math\n", + "\n", + "\n", + "# all code in this block from lectures #\n", + "\n", + "\n", + "def arange(x_min, x_max, steps=10):\n", + " step_size = (x_max - x_min) /steps\n", + " x = x_min\n", + " out = list()\n", + " for i in range(steps):\n", + " out.append(x)\n", + " x += step_size\n", + " return out\n", + "\n", + "\n", +======= "import math,random\n", "\n", "def arange(x_min,x_max,steps=10):\n", @@ -133,6 +349,7 @@ " x+=step_size\n", " return out\n", "\n", +>>>>>>> dd964aa33bbeea4d02fcfdd92e806792198daa05 "def generate_normal(N,m=0,s=1):\n", " out = list() \n", " \n", @@ -169,10 +386,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 130, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1.3119894260482794\n", + " x_90: 1.311989\n", + "under x_90: 90.0%\n" + ] + } + ], + "source": [ + "def find_x_90(x):\n", + " h = histogram(x, len(x))\n", + " N = float(len(x))\n", + " x_90 = h[1][1] # second to lowest edge by default\n", + " for i in range(1, len(h[0])):\n", + " if cumulative_sum(h[0][:i])[-1] < 0.9*N:\n", + " x_90 = h[1][i+1]\n", + " else:\n", + " break\n", + " return x_90\n", + "\n", + "x = generate_normal(1000)\n", + "x_90 = find_x_90(x)\n", + "hist = histogram(x,len(x))\n", + "print(hist[1][hist[1].index(x_90)])\n", + "print(\" x_90: {:f}\".format(x_90))\n", + "print(\"under x_90: {:3.1f}%\".format(100 * cumulative_sum(hist[0][:hist[1].index(x_90)])[-1]/len(x)))\n" + ] } ], "metadata": { @@ -191,7 +436,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.1" + "version": "3.7.2" } }, "nbformat": 4, diff --git a/Labs/Lab-1/Copy_of_Lab_1.ipynb b/Labs/Lab-1/Copy_of_Lab_1.ipynb new file mode 100644 index 0000000..cab1a58 --- /dev/null +++ b/Labs/Lab-1/Copy_of_Lab_1.ipynb @@ -0,0 +1,1138 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-1.ipynb", + "provenance": [], + "collapsed_sections": [], + "toc_visible": true + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "O5vg8KKRq0sy", + "colab_type": "text" + }, + "source": [ + "# Lab 1\n", + "\n", + "## Python Notebooks on Google Colab\n", + "\n", + "Data 1401's Labs, Homework, and Exams will be all in form of iPython notebooks. You may already be familiar with python notebooks if you have used Jupyter before, for example in Data 1301. If so, you are welcome to use whatever means you have to run Jupyter notebooks for this course, though you may get limited support. Our primary means of running python notebooks will be through [Google Colab](https://colab.research.google.com) and we will be storing files on google drive.\n", + "\n", + "You will need a google account. If you do not have one or you wish to use a different account for this course, please follow [these instructions](https://edu.gcfglobal.org/en/googledriveanddocs/getting-started-with-google-drive/1/) to make an account.\n", + "\n", + "Once you are ready with your account, you can continue in Colab. Click on the following badge to open this notebook in Colab:\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-1/Lab-1.ipynb)\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "mm8NAwqDBt7L", + "colab_type": "code", + "outputId": "2f2e6a3a-5416-43d7-e26e-930e447467f0", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 122 + } + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n", + "\n", + "Enter your authorization code:\n", + "··········\n", + "Mounted at /content/drive\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FVt_1hPt1dAK", + "colab_type": "text" + }, + "source": [ + "## Notebooks in Colab\n", + "\n", + "You now are presumably in Colab. Word of caution, by default, Google Colab does not save your notebooks, so if you close your session, you will loose your work.\n", + "\n", + "So first thing: from the file menu above select \"Save a copy in Drive\"." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x0JBL_RFrDDj", + "colab_type": "text" + }, + "source": [ + "## Storing Notebooks in Google Drive\n", + "A better way to work is to save your notebooks directly into Google Drive and upload directly to Git (where you will be downloading and uploading your homework). In order properly setup Git, we'll need to work more directly in your Google Drive.\n", + "\n", + "On the left sidebar, press the file icon to see a listing of files accessibile to this Notebook. Then press \"Mount Drive\" and follow the instructions to mount your Google Drive in this notebook. A new cell will be inserted into this notebook, which after you run by pressing the play button will instruct you to follow a link to log into your Google Account and enable access to your Drive in another tab. Finally you will copy a link from the new tab back into the cell in this notebook. Once you are done, press refresh under files in the left sidebar and you should have \"drive/My Drive\" appear." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hwJ6wJk3tiLv", + "colab_type": "text" + }, + "source": [ + "## Github\n", + "All the class material will be stored on github. You will also submit your homework using github. To do so, you will need a github account.\n", + "\n", + "If you do not already have a github account or wish to create a new one for this course, create one:\n", + "* Browse to [github.com](https://github.com).\n", + "* Click the green “Sign up for GitHub”\tbutton.\n", + "* Follow instructions for creating an account.\n", + "* Make sure you remember your github username and password.\n", + "\n", + "Write an email to the course TA titled \"Data 1401: Github account\" with your github username (not your password) as the contents.\n", + "\n", + "## Google Groups\n", + "\n", + "Class annoucements will be made via google groups. If you did not already receive an invite to the class google group, had trouble with the invite, or wish to use a different email address, write an email to the course TA titled \"Data 1401: Google Group\" with your preferred email.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TjfIzdQZqvzk", + "colab_type": "text" + }, + "source": [ + "## Introduction: Unix, Git, and Jupyter\n", + "\n", + "This lab aims to introduce you to basic Unix, familiarize you with iPython notebooks and get you setup to submit your homework.\n", + "*italicized text*" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C_LmOgzFqvzp", + "colab_type": "text" + }, + "source": [ + "\n", + "\n", + "### Terminal, Shell, and ssh\n", + "\n", + "\n", + "The terminal is a simple program that generally runs another program, taking mostly keyboard input from you, passing it to this other program, and taking the output of the program and displaying on the screen for you.\n", + "\n", + "The terminal usually runs a program called a shell. Shells present a command prompt where you can type in commands, which are then executed when you press enter. In most shells, there are some special commands which the shell will execute. Everything else you type in, the shell will assume is a name of a program you want to run and arguments you want to pass that program. So if the shell doesn't recognize something you type in, it'll try to find a program with a name that is the same as the first word you gave it. \n", + "\n", + "### Shell in Colab\n", + "\n", + "Unfortunately, google Colab does not allow you to open a terminal window. Jupyter does, so if you are running in Jupyter (which most of you will not be), you may choose to open a terminal window by returning to the jupyter file list tab and selecting new terminal from the top right.\n", + "\n", + "For Colab, we will have to do something non-ideal, but functional. There are several ways to execute shell commands from within a python notebook. For example, you can use any shell command by putting \"!\" in front of the command:\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "KJ5f-WO0wcAv", + "colab_type": "code", + "outputId": "2f31b640-40cf-44fb-f705-f0549d502518", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "!ls\n", + "!echo \"----------\"\n", + "!ls sample_data" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "drive sample_data\n", + "----------\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8f-n4AXFw-dD", + "colab_type": "text" + }, + "source": [ + "Unfortunately, every time you use \"!\" a new environment is created and the state reverted to the original state. Try to understand the difference between the following two sets of commands:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "99nrBYTWxZJr", + "colab_type": "code", + "outputId": "26a2b96c-1381-4dca-ff10-b6d6ef3e1a82", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + } + }, + "source": [ + "!echo \"Technique 1:\"\n", + "!ls\n", + "!cd sample_data\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 1:\n", + "drive sample_data\n", + "drive sample_data\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2-Znf97Lxl-Z", + "colab_type": "code", + "outputId": "7d739354-6bcd-4934-b3e9-8884feb28994", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "!echo \"Technique 2:\"\n", + "!ls ; cd sample_data ;ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 2:\n", + "drive sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4x9n1rAkxyYl", + "colab_type": "text" + }, + "source": [ + "Notebooks allow a bit of \"magic\" (using \"%\") to avoid some of these limitations:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vLBPTX4rx3gd", + "colab_type": "code", + "outputId": "c459c076-c2d7-4149-834a-b9e2903c2a1a", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "!echo \"Technique 3:\"\n", + "!ls \n", + "%cd sample_data \n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 3:\n", + "drive sample_data\n", + "/content/sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "U8XpvPjcyH0w", + "colab_type": "text" + }, + "source": [ + "For our purposes, we are just going to explicitly start a new shell and interact with it in the output cell. Execute the following cell. You will be able to type and execute commands. Look around a bit using \"ls\" and \"cd. You can stop the cell from running by typing \"exit\"." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "MIDFitLZyuZy", + "colab_type": "code", + "outputId": "5a308bc9-fa60-4821-8108-e8112b82c468", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (120): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# pwd\n", + "/content/sample_data\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# which ls\n", + "/bin/ls\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ls /bin\n", + "\u001b[0m\u001b[01;32mbash\u001b[0m \u001b[01;32mjournalctl\u001b[0m \u001b[01;32msync\u001b[0m\n", + "\u001b[01;32mbunzip2\u001b[0m \u001b[01;32mkill\u001b[0m \u001b[01;32msystemctl\u001b[0m\n", + "\u001b[01;32mbzcat\u001b[0m \u001b[01;32mkmod\u001b[0m \u001b[01;36msystemd\u001b[0m\n", + "\u001b[01;36mbzcmp\u001b[0m \u001b[01;32mless\u001b[0m \u001b[01;32msystemd-ask-password\u001b[0m\n", + "\u001b[01;32mbzdiff\u001b[0m \u001b[01;32mlessecho\u001b[0m \u001b[01;32msystemd-escape\u001b[0m\n", + "\u001b[01;36mbzegrep\u001b[0m \u001b[01;36mlessfile\u001b[0m \u001b[01;32msystemd-hwdb\u001b[0m\n", + "\u001b[01;32mbzexe\u001b[0m \u001b[01;32mlesskey\u001b[0m \u001b[01;32msystemd-inhibit\u001b[0m\n", + "\u001b[01;36mbzfgrep\u001b[0m \u001b[01;32mlesspipe\u001b[0m \u001b[01;32msystemd-machine-id-setup\u001b[0m\n", + "\u001b[01;32mbzgrep\u001b[0m \u001b[01;32mln\u001b[0m \u001b[01;32msystemd-notify\u001b[0m\n", + "\u001b[01;32mbzip2\u001b[0m \u001b[01;32mlogin\u001b[0m \u001b[01;32msystemd-sysusers\u001b[0m\n", + "\u001b[01;32mbzip2recover\u001b[0m \u001b[01;32mloginctl\u001b[0m \u001b[01;32msystemd-tmpfiles\u001b[0m\n", + "\u001b[01;36mbzless\u001b[0m \u001b[01;32mls\u001b[0m \u001b[01;32msystemd-tty-ask-password-agent\u001b[0m\n", + "\u001b[01;32mbzmore\u001b[0m \u001b[01;32mlsblk\u001b[0m \u001b[01;32mtar\u001b[0m\n", + "\u001b[01;32mcat\u001b[0m \u001b[01;36mlsmod\u001b[0m \u001b[01;32mtempfile\u001b[0m\n", + "\u001b[01;32mchgrp\u001b[0m \u001b[01;32mmkdir\u001b[0m \u001b[01;32mtouch\u001b[0m\n", + "\u001b[01;32mchmod\u001b[0m \u001b[01;32mmknod\u001b[0m \u001b[01;32mtrue\u001b[0m\n", + "\u001b[01;32mchown\u001b[0m \u001b[01;32mmktemp\u001b[0m \u001b[01;32mudevadm\u001b[0m\n", + "\u001b[01;32mcp\u001b[0m \u001b[01;32mmore\u001b[0m \u001b[01;32mulockmgr_server\u001b[0m\n", + "\u001b[01;32mdash\u001b[0m \u001b[37;41mmount\u001b[0m \u001b[37;41mumount\u001b[0m\n", + "\u001b[01;32mdate\u001b[0m \u001b[01;32mmountpoint\u001b[0m \u001b[01;32muname\u001b[0m\n", + "\u001b[01;32mdd\u001b[0m \u001b[01;32mmv\u001b[0m \u001b[01;32muncompress\u001b[0m\n", + "\u001b[01;32mdf\u001b[0m \u001b[01;32mnetworkctl\u001b[0m \u001b[01;32mvdir\u001b[0m\n", + "\u001b[01;32mdir\u001b[0m \u001b[01;36mnisdomainname\u001b[0m \u001b[01;32mwdctl\u001b[0m\n", + "\u001b[01;32mdmesg\u001b[0m \u001b[01;36mpidof\u001b[0m \u001b[01;32mwhich\u001b[0m\n", + "\u001b[01;36mdnsdomainname\u001b[0m \u001b[01;32mps\u001b[0m \u001b[01;36mypdomainname\u001b[0m\n", + "\u001b[01;36mdomainname\u001b[0m \u001b[01;32mpwd\u001b[0m \u001b[01;32mzcat\u001b[0m\n", + "\u001b[01;32mecho\u001b[0m \u001b[01;36mrbash\u001b[0m \u001b[01;32mzcmp\u001b[0m\n", + "\u001b[01;32megrep\u001b[0m \u001b[01;32mreadlink\u001b[0m \u001b[01;32mzdiff\u001b[0m\n", + "\u001b[01;32mfalse\u001b[0m \u001b[01;32mrm\u001b[0m \u001b[01;32mzegrep\u001b[0m\n", + "\u001b[01;32mfgrep\u001b[0m \u001b[01;32mrmdir\u001b[0m \u001b[01;32mzfgrep\u001b[0m\n", + "\u001b[01;32mfindmnt\u001b[0m \u001b[01;32mrun-parts\u001b[0m \u001b[01;32mzforce\u001b[0m\n", + "\u001b[37;41mfusermount\u001b[0m \u001b[01;32msed\u001b[0m \u001b[01;32mzgrep\u001b[0m\n", + "\u001b[01;32mgrep\u001b[0m \u001b[01;36msh\u001b[0m \u001b[01;32mzless\u001b[0m\n", + "\u001b[01;32mgunzip\u001b[0m \u001b[01;36msh.distrib\u001b[0m \u001b[01;32mzmore\u001b[0m\n", + "\u001b[01;32mgzexe\u001b[0m \u001b[01;32msleep\u001b[0m \u001b[01;32mznew\u001b[0m\n", + "\u001b[01;32mgzip\u001b[0m \u001b[01;32mstty\u001b[0m\n", + "\u001b[01;32mhostname\u001b[0m \u001b[37;41msu\u001b[0m\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# printenv\n", + "CUDNN_VERSION=7.6.5.32\n", + "LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.xspf=00;36:\n", + "LD_LIBRARY_PATH=/usr/local/nvidia/lib:/usr/local/nvidia/lib64\n", + "LESSCLOSE=/usr/bin/lesspipe %s %s\n", + "LANG=en_US.UTF-8\n", + "HOSTNAME=a2026fa2008e\n", + "OLDPWD=/\n", + "CLOUDSDK_CONFIG=/content/.config\n", + "NVIDIA_VISIBLE_DEVICES=all\n", + "DATALAB_SETTINGS_OVERRIDES={\"kernelManagerProxyPort\":6000,\"kernelManagerProxyHost\":\"172.28.0.3\",\"jupyterArgs\":[\"--ip=\\\"172.28.0.2\\\"\"]}\n", + "ENV=/root/.bashrc\n", + "PAGER=cat\n", + "NCCL_VERSION=2.4.8\n", + "TF_FORCE_GPU_ALLOW_GROWTH=true\n", + "JPY_PARENT_PID=24\n", + "NO_GCE_CHECK=True\n", + "PWD=/content/sample_data\n", + "HOME=/root\n", + "LAST_FORCED_REBUILD=20191217\n", + "CLICOLOR=1\n", + "DEBIAN_FRONTEND=noninteractive\n", + "LIBRARY_PATH=/usr/local/cuda/lib64/stubs\n", + "GLIBCPP_FORCE_NEW=1\n", + "TBE_CREDS_ADDR=172.28.0.1:8008\n", + "SHELL=/bin/bash\n", + "TERM=xterm-color\n", + "GCS_READ_CACHE_BLOCK_SIZE_MB=16\n", + "PYTHONWARNINGS=ignore:::pip._internal.cli.base_command\n", + "MPLBACKEND=module://ipykernel.pylab.backend_inline\n", + "CUDA_PKG_VERSION=10-1=10.1.243-1\n", + "CUDA_VERSION=10.1.243\n", + "NVIDIA_DRIVER_CAPABILITIES=compute,utility\n", + "SHLVL=3\n", + "PYTHONPATH=/env/python\n", + "NVIDIA_REQUIRE_CUDA=cuda>=10.1 brand=tesla,driver>=384,driver<385 brand=tesla,driver>=396,driver<397 brand=tesla,driver>=410,driver<411\n", + "COLAB_GPU=0\n", + "GLIBCXX_FORCE_NEW=1\n", + "PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin\n", + "LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libtcmalloc.so.4\n", + "LESSOPEN=| /usr/bin/lesspipe %s\n", + "GIT_PAGER=cat\n", + "_=/usr/bin/printenv\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# echo $SHELL\n", + "/bin/bash\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# \n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# \n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# \n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ^C\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q-4hfZBywW25", + "colab_type": "text" + }, + "source": [ + "While in this instance your shell is running in a this notebook, you can also run terminals natively on your own computer. On Linux or MacOS, you just have to run a program called terminal. In Windows you can start a \"command prompt\". \n", + "\n", + "\n", + "Type in \"ls\" into the terminal and press enter. The shell will find a program called \"ls\", a standard tool in Unix, and run it. \"ls\" lists the contents (files and directories) of your current directory. If you are just starting in this course, you probably only see the git repository you cloned. \n", + "\n", + "A subtle point to realize here is that while the terminal is running in the browser that is running on the computer in front of you, the shell is actually running on a machine on google hardware. The shell prompt typically displays the name of the machine you are using. What you are not seeing is that there is an intermidate program between the terminal running on your computer and the shell running on google. This intermidary program is taking your input from the terminal sending it over the network to google and bringing back the responses for you terminal to display.\n", + "\n", + "A bit of extra information. If you start a terminal on your own computer, the shell runs locally. The \"ls\" command would then list contents of a directory on your computer. You can typically connect to Unix computers by evoking a shell running on that machine over the network. In this case, you would have to initiate this intermidiary program yourself. The program is called \"ssh\" (secure shell). You can \"ssh\" to another machine from your machine, by simply typing \"ssh\" followed by the machine name or IP address. Most likely you would be prompted for a password, after which you would dropped into the prompt of a shell running on the remote machine. \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "51Eya4LBqvzs", + "colab_type": "text" + }, + "source": [ + "## Programs and Environment Variables\n", + "\n", + "You have a listing of your current directory, but you don't know where that directory resides. You can see what directory you are using the command \"pwd\" (print working directory). Issue the command and look at the response. You'll get a slash (\"/\") separated list, known as the path, of the directory hierarchy of your current working directory. On Colab, this will start with \"contents\"\n", + "\n", + "Now back to thinking about the command prompt. Since \"ls\" is a program, it most be stored somewhere. It is clearly not in your working directory, because you didn't see it when you executed \"ls\". We can ask the shell to tell us where it found \"ls\" using the \"which ls\" command. Note that \"which\" is also a program. \"which ls\" comes back with \"/bin/ls\", telling you the \"ls\" program is sitting in \"/bin\" directory of the system. \n", + "\n", + "Lets see what else is in there by issuing a \"ls /bin\" command. You will get a long list of programs. You can run any of these programs by just typing their names and pressing enter. You may be able to guess what some of these programs do, but if you want to know, most of them provide you help, using \"--help\" or \"-h\" flag. For example execute \"ls --help\". For more information about a program or command, you can use Unix's manual pages using the \"man\" command. Try typing \"man ls\". Note that you will need to press space to scroll through lengthy manual pages and \"q\" to exit back to the shell prompt. \n", + "\n", + "Another command interesting is \"echo\". \"echo\" simply prints whatever you put after it to the screen. Try executing \"echo Hello World.\"\n", + "\n", + "At this point, you may wonder how was it that the shell knew to look for programs in \"/bin\"? The shell keeps a list of places to look for programs an environment variable with the name \"PATH\". The shell keeps a table that map string variable names to string expressions. When the shell starts, its configuration files set some environment variables that it uses. You can see the full list of defined environment variables using the command \"printenv\".\n", + "\n", + "You can use a environment variable in a shell by prepending name of the variable with a dollar sign character (\"\\$\"). So you can print out the PATH environment variable using the command \"echo $PATH\". What you will see is a colon (\":\") separated list of directories that the shell will search (in order) whenever you type in anything.\n", + "\n", + "You can set you own environment variables. Different shells have different syntax. Lets first figure out what shell we are running. \n", + "\n", + "*Exercise 1:* Use the \"echo\" command to print out the value of the \"SHELL\" environment variable:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YS7YFiPwqvzu", + "colab_type": "text" + }, + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "QtAUpDAWNjyj", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash -noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YoEgruUhqvzw", + "colab_type": "text" + }, + "source": [ + "## Navigating Directories\n", + "\n", + "You can change your current directory using the \"cd\" shell command. Note that \"cd\" is not a Unix program. Once in a directory, you can use the \"ls\" command to list the contents or \"pwd\" to remind yourself your current working directory. You can move back one level in your current directory hierarchy using \"cd ..\". In general \"..\" represents the path to a directory one level above your current directory, \"../..\" represents two levels up, and so on. \".\" represents the current directory. If you look at the PATH environment variable, you'll notice that the last item is \".\", telling the shell to look into your current directory for commands. Finally the \"~\" character always refers to your home directory.\n", + "\n", + "Some other file manipulation commands:\n", + "\n", + " - The \"mkdir\" command creates new directories. \n", + " - \"cp\" and \"mv\" allow you to copy and move (or rename) files, taking 2 arguments: the original path/filename and the target path/filename. \n", + " - The \"rm\" and \"rmdir\" commands remove (delete) files and directories.\n", + "\n", + "\n", + "*Exercise 2:* Using the \"cd\" command, navigate into \"drive/My\\ Drive\" directory. Create a new directory called \"Data-1441\", and another directory inside \"Data-1441\" called \"Lab-1-Solutions\". Perform the rest of the lab in this directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "A16VzZ3G0J8x", + "colab_type": "code", + "outputId": "d599ec86-6d8a-49cd-af4b-cc6721b318a6", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (120): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a2026fa2008e: /content/sample_data\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ../drive/My\\ Drive\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# mkdir Data-1441\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1441\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# ls\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# mkdir Lab-1-Solutions\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o38c4lbsqvzy", + "colab_type": "text" + }, + "source": [ + "## Exploring Unix Filesystem\n", + "\n", + "You can look at the root directory of the system by issuing \"ls /\". As explained in lecture, Unix uses the file system to communicate with devices and between processes. \"/etc\" keeps the configuration files of the system. \"/bin\" and \"/sbin\" store most of the standard Unix programs. \"/usr\" stores installes programs and their associate files, with \"/usr/bin\" usually storing the commands you can run. \n", + "\n", + "*Exercise 3:* List the \"/dev\" directory. How many SSD storage devices do you see? How many partitions does each device have? (Answer in box below)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yNj2LXzP2ksl", + "colab_type": "code", + "outputId": "3b32b8ca-0a31-4e55-ecab-1ea3b0e9aa44", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + } + }, + "source": [ + "!/bin/bash --noediting\n", + "# 1 storage device, 12 partitons" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (120): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# lssda\n", + "bash: lssda: command not found\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# lsda\n", + "bash: lsda: command not found\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# lsblk\n", + "NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\n", + "loop0 7:0 0 110G 0 loop \n", + "sda 8:0 0 120G 0 disk \n", + "├─sda1 8:1 115.9G 0 part /etc/hosts\n", + "├─sda2 8:2 0 16M 0 part \n", + "├─sda3 8:3 0 2G 0 part \n", + "├─sda4 8:4 0 16M 0 part \n", + "├─sda5 8:5 0 2G 0 part \n", + "├─sda6 8:6 512B 0 part \n", + "├─sda7 8:7 0 512B 0 part \n", + "├─sda8 8:8 16M 0 part \n", + "├─sda9 8:9 0 512B 0 part \n", + "├─sda10 8:10 0 512B 0 part \n", + "├─sda11 8:11 8M 0 part \n", + "└─sda12 8:12 0 32M 0 part \n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7P9EG0KOqvz2", + "colab_type": "text" + }, + "source": [ + "## Text File Manipulation\n", + "\n", + "As explained in lecture, Unix stores most information in text files. For example, the list of all users and their home directories are stored in \"/etc/passwd\". Let get some familiarity with the most commonly used commands to manipulate files.\n", + "\n", + " - You can see the contents contents a file using the \"cat\" (concatenate) command. Try executing \"cat /etc/passwd\". You'll get a huge list that will go by your screen quickly. \n", + " \n", + " - To go through the file page by page, you can use the \"less\" or \"more\" commands. \n", + " \n", + " - You can see the first or last N (N=10 by default) lines of a file using \"head\" or \"tail\" commands. For example \"tail -20 /etc/passwd\" will list the last 20 lines. \n", + " \n", + " - You can search a test file using the \"grep\" command, which takes a string keyword as the first argument and a filename as the second, and by default prints out every line in the file that contrains the string. So for example you can do \"grep \\$USER /etc/passwd\" to find the line corresponding to your account. Some useful flags: \n", + " \n", + " - \"-i\" ignores the case of the keyword\n", + " - \"-v\" display those lines that do NOT match \n", + " - \"-n\" precede each matching line with the line number \n", + " - \"-c\" print only the total count of matched lines \n", + " \n", + " For example \"grep -c \\$USER /etc/passwd\" should show that you are in the password file just once. \n", + " \n", + " - The \"wc\" (word count) command counts the number of lines, words, and characters in a file. By default \"wc\" gives you all three numbers, but \"-w\", \"-l\", or \"-c\" flags \n", + "\n", + "*Exercise 4:* Count how many lines in the password file contain the letter \"w\". " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "UlsANMuf2qMs", + "colab_type": "code", + "outputId": "15574af9-3dd4-4634-efe4-9804c090b6ac", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "!/bin/bash --noediting\n", + "# 3" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (120): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# grep -ic w /etc/passwd\n", + "3\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SZuhLbD8qvz5", + "colab_type": "text" + }, + "source": [ + "## Redirection\n", + "\n", + "Unix provides programs \"pipes\" for input and output. Most of what you see on the screen when you run a program was written to the \"stdout\" (standard output) pipe. Other pipes are \"stdin\" (standard input) and \"stderr\" (standard error), where error messages are written.\n", + "\n", + "As discussed in lecture, the basic commands of are simple, but you can chain them to do complicated things. Redirection is how you chain these commands, directing the output of one command to the input of the next.\n", + "\n", + "As an example, consider the \"cat\" command. Cat takes stdin and outputs it to stdout. Type \"cat\" and press enter and confirm. You can get back to the command prompt by pressing \"control-c\" (sends terminate singal) or \"control-d\" (end of file character). Note that from now on we will use the convention: \"control-d\" = \"^D\"\n", + "\n", + "*Exercise 5a:* Using \"cat\" and indirection you can write things into a file. The \">\" symbol directs stdout into a file. Try \"cat > favorite-colors-list.txt\" and then type in your 3 favorite colors, each on it's own line. Use \"^D\" to end your input." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H5vxtcXnqvz6", + "colab_type": "text" + }, + "source": [ + "Use \"cat\", \"more\", or \"less\" to confirm that you file is as you expect it. \">>\" allows you to append to the file. \n", + "\n", + "*Exercise 5b:* Append 2 more colors to your file." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "twRKNaGy3XGw", + "colab_type": "code", + "outputId": "a1ddc514-a73c-4686-e2b1-4f3777fe3000", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 221 + } + }, + "source": [ + "!/bin/bash --noediting\n", + "# white\n", + "# black\n", + "# red\n", + "# blue\n", + "# orange" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (120): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# cat > favorite-colors-list.txt\n", + "white\n", + "black\n", + "red\n", + "\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# cat >> favorite-colors-list.txt\n", + "blue\n", + "orange\n", + "\n", + "\u001b]0;root@a2026fa2008e: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@a2026fa2008e\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# ^C\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DZODNKiAqvz8", + "colab_type": "text" + }, + "source": [ + "The \"sort\" command sorts what it sees on stdin. Instead of taking input from the terminal, you can direct the shell to take stdin from a file using \"<\". Try \"sort < favorite-color-list.txt\" and \"sort < favorite-color-list.txt > sorted-favorite-color-list.txt\".\n", + "\n", + "Finally, instead of piping input / output into files, you can directly chain one program into another using \"|\". So for example, you can do \"cat /etc/passwd | grep -i \\$USER | wc -l\". \n", + "\n", + "*Exercise 5c:* Use indirection to count the number of users on TACC with your first name. Copy the command you used into box below." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "oP9XlZl_3iZD", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v5IaZXNyqvz_", + "colab_type": "text" + }, + "source": [ + "## Git\n", + "\n", + "`git` is a Version Control System (VCS), typically used to organize the source code of software project but also good source of documents or web-pages. An instance of `git` server stores repositories, each typically containing the code relevant to a specific project. Users create local `clones` of repositories, change and develop the local copies of the code, `commit` the changes to their local repository, `push` to the server as a contribution, \n", + "`pull` updates from the server, and `merge` changes between local and remote versions. \n", + "\n", + "Besides cloning, repositories can be branched or forked. A repository generally starts with a `master` branch that evolves as push requests are merged in. Creating a new branch from an existing branch creates a snapshot of the which can evolve independently or be merged in later. Branches are easy to make and delete, and can serve various purposes. They can represent a stable version of software package. Or a parallel development for different operating system. A fork of a repository is a standalone instance of the repository which can be stored and managed independently from the original, where you can work independently without constraints or interference. \n", + "\n", + "[GitHub](github.com) provides a massive publically accessible instance of a `git` system besides sharing code, projects can be developed by the open source community. It provides tools for managing your repository and a wiki for documentation. Contributions to public software on GitHub generally require making a merge request which would be judged by the managers of the repository. That's why most software packages enourage you to create a new fork, so you can work independently.\n", + "\n", + "Lets take a look at some repositories:\n", + "\n", + "* [This class](https://github.com/afarbin/DATA1401-Spring-2020)\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J_R64sQDqv0A", + "colab_type": "text" + }, + "source": [ + "## Plan\n", + "\n", + "You made a clone of the class repository at start of this lab. We will create a new fork where you can keep track and submit your work, following [these instructions](https://help.github.com/articles/fork-a-repo/).\n", + "\n", + "Goto to github.com and log in.\n", + "\n", + "Next, lets create a fork of the [class repository](https://github.com/afarbin/DATA1401-Spring-2019). Click the link and press the \"Fork\" button on the top right. Select your repository as where you want to place the fork.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "edTvE6rOqv0C", + "colab_type": "text" + }, + "source": [ + "Now we will check out your fork in your Google Drive / Colab.\n", + "\n", + "Note: Jupyter allows you to run shell directly in a notebook. We will use `!` and `%` to call shell commands directly in this notebook. Follow along yourself. Either create a new notebook or open a terminal. \n", + "\n", + "Start by listing the contents of your current directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "e5tXg0f8qv0D", + "colab_type": "code", + "outputId": "6fa0b41a-aeb3-4de6-bd5d-511ca8afd957", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 442 + } + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive\n", + " 0E84CCE9-ED53-4F31-B77C-6496E957ED04.jpeg\n", + " 51FD2468-94A1-4F13-974E-508BDD804C73.jpeg\n", + " A6A4BE08-543B-4088-941D-B6EF032E84E3.jpeg\n", + "'All Files'\n", + " Biothing.gdoc\n", + "'Colab Notebooks'\n", + " Conquest_1.8.zip\n", + "'Conquest Models.zip'\n", + "'Copy of The One Page Novel Scene Spreadsheet.gsheet'\n", + "'Copy of Vicentio.gslides'\n", + " Data-1441\n", + " Factorio.zip\n", + "'Gears v27.dwg'\n", + "'Gears v31.dwg'\n", + "'HWN Proposed Silent Auction Basket Themes.gdoc'\n", + "'May 2016 Newsletter.pdf'\n", + " MCArch\n", + "'[MV] IU(아이유) _ Friday(금요일에 만나요) (Feat. Jang Yi-jeong(장이정) of HISTORY(히스토리)).mp3'\n", + "'Provide Access to Clean Water.gslides'\n", + " resources.zip\n", + "\"Samson's Reflection.gdoc\"\n", + "'Text File (1).txt'\n", + "'Text File.txt'\n", + " TIG-1_zpse93244e6.JPG.crdownload\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WYsyYcg1qv0J", + "colab_type": "text" + }, + "source": [ + "Make a new directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Z7noY1hMqv0L", + "colab_type": "code", + "outputId": "c215b7ad-276d-4e34-baba-66b394c877ab", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fwsBdTnYqv0Q", + "colab_type": "text" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8w42MH6Jqv0S", + "colab_type": "code", + "outputId": "e274141d-df09-4a6a-8599-e8d9867e6320", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "# What you past here should look like:\n", + "!git clone https://github.com/sammysamsamsama/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Cloning into 'DATA1401-Spring-2020'...\n", + "remote: Enumerating objects: 24, done.\u001b[K\n", + "remote: Counting objects: 100% (24/24), done.\u001b[K\n", + "remote: Compressing objects: 100% (16/16), done.\u001b[K\n", + "remote: Total 24 (delta 3), reused 23 (delta 2), pack-reused 0\u001b[K\n", + "Unpacking objects: 100% (24/24), done.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cOAuqTVUqv0V", + "colab_type": "text" + }, + "source": [ + "Go into the directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "b1Ew4tEZqv0X", + "colab_type": "code", + "outputId": "dd96ce57-cc07-472a-81c2-8e99bceb9276", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "%cd DATA1401-Spring-2020\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo/DATA1401-Spring-2020\n", + "Labs Lectures\tREADME.md syllabus.pdf\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IrhWToc-qv0a", + "colab_type": "text" + }, + "source": [ + "We will now connect your fork to the original so you can pull changes from there. \n", + "\n", + "Check remote status:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JxtMYR-9qv0c", + "colab_type": "code", + "outputId": "94194753-9622-4048-c4e2-e5a7ef408b4e", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/sammysamsamsama/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/sammysamsamsama/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9ud3X0fBqv0f", + "colab_type": "text" + }, + "source": [ + "Now use the original class URL to set your upstream:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "pgJlKxBqqv0h", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "id2yUEt9qv0k", + "colab_type": "code", + "outputId": "8afb6720-d840-4dfa-f46a-fd14eba94241", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/sammysamsamsama/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/sammysamsamsama/DATA1401-Spring-2020.git (push)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (fetch)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sAkgeJ6Iqv0n", + "colab_type": "text" + }, + "source": [ + "From now on, you can get the newest version of class material by using:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AGDsfTFLqv0o", + "colab_type": "code", + "outputId": "517b1d5d-059d-46b0-b416-f4b0c3f5d17f", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!git pull" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Already up to date.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u9RAhs5b4vXY", + "colab_type": "text" + }, + "source": [ + "We will submit your Lab 1 using git at the next Lab." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PPfGmFQI40HR", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-2/Copy_of_Lab_2.ipynb b/Labs/Lab-2/Copy_of_Lab_2.ipynb new file mode 100644 index 0000000..d09d7b5 --- /dev/null +++ b/Labs/Lab-2/Copy_of_Lab_2.ipynb @@ -0,0 +1,1263 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-2.ipynb", + "provenance": [], + "collapsed_sections": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "uk7yc0nadBGa", + "colab_type": "text" + }, + "source": [ + "# Lab 2\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-2/Lab-2.ipynb)\n", + "\n", + "## Submitting lab solutions\n", + "\n", + "At the end of the previous lab, you should have set up a \"Solutions\" directory in your Google Drive, with a fork of the class git repository that pull from Dr. Farbin's verison and pushes to your own fork. \n", + "\n", + "Unfortunately due to a typo in the previous lab, you probably forked the 2019 version of the gitlab repository for this course. Unless you noticed and corrected the error, you'll have to fork again.\n", + "\n", + "In addition, due to some problems with the setup in Google Colab, we will be submitting our solutions to your fork using the web interface. Instructions on how to use the command-line are in this notebook, but we suggest you do not follow them unless you are working in a jupyter notebook and not Google Colab." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "J4gOp2tXCSLG", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 122 + }, + "outputId": "f491886d-d46c-4e45-e2d5-b63435df0493" + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n", + "\n", + "Enter your authorization code:\n", + "··········\n", + "Mounted at /content/drive\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OMNaOnRksNK3", + "colab_type": "text" + }, + "source": [ + "You may also choose to delete the fork from your GitHub account. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "J_R64sQDqv0A" + }, + "source": [ + "## Repeating last steps of Lab 1\n", + "\n", + "### Create your own fork\n", + "We will create a new fork where you can keep track and submit your work, following [these instructions](https://help.github.com/articles/fork-a-repo/).\n", + "\n", + "Goto to github.com and log in.\n", + "\n", + "Next, create a fork of the [2020 class repository](https://github.com/afarbin/DATA1401-Spring-2020). Click the link and press the \"Fork\" button on the top right. Select your repository as where you want to place the fork.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "edTvE6rOqv0C" + }, + "source": [ + "### Make a local clone (Advanced)\n", + "\n", + "Before we get started, please mount your Google Drive using by clicking the file icon on the left, then clicking \"Mount Drive\", and following the instructions as you did in the previous lab.\n", + "\n", + "If you did complete Lab 1 and therefore created a 2019 fork and a local clone in you Google Drive, delete the local clone:\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2u6B-rfNr1wN", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!rm -rf drive/My\\ Drive/Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BDVI5nu8-2RH", + "colab_type": "text" + }, + "source": [ + "Now we will check out your fork in your Google Drive / Colab. If you will be doing everything on your own computer instead of Google Colab/Drive, you are welcome to install Git on your computer and perform the following steps (appropriately modified) on your computer instead.\n", + "\n", + "Start by listing the contents of your current directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "e5tXg0f8qv0D", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 459 + }, + "outputId": "2800d429-d35d-4cad-a756-892511d54780" + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive\n", + " 0E84CCE9-ED53-4F31-B77C-6496E957ED04.jpeg\n", + " 51FD2468-94A1-4F13-974E-508BDD804C73.jpeg\n", + " A6A4BE08-543B-4088-941D-B6EF032E84E3.jpeg\n", + "'All Files'\n", + " Biothing.gdoc\n", + "'Colab Notebooks'\n", + " Conquest_1.8.zip\n", + "'Conquest Models.zip'\n", + "'Copy of The One Page Novel Scene Spreadsheet.gsheet'\n", + "'Copy of Vicentio.gslides'\n", + " Data-1401-Repo\n", + " Data-1441\n", + " Factorio.zip\n", + "'Gears v27.dwg'\n", + "'Gears v31.dwg'\n", + "'HWN Proposed Silent Auction Basket Themes.gdoc'\n", + "'May 2016 Newsletter.pdf'\n", + " MCArch\n", + "'[MV] IU(아이유) _ Friday(금요일에 만나요) (Feat. Jang Yi-jeong(장이정) of HISTORY(히스토리)).mp3'\n", + "'Provide Access to Clean Water.gslides'\n", + " resources.zip\n", + "\"Samson's Reflection.gdoc\"\n", + "'Text File (1).txt'\n", + "'Text File.txt'\n", + " TIG-1_zpse93244e6.JPG.crdownload\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "WYsyYcg1qv0J" + }, + "source": [ + "Make a new directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "Z7noY1hMqv0L", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "97d59400-1725-49b2-d381-cb2749516a1b" + }, + "source": [ + "#!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "fwsBdTnYqv0Q" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "8w42MH6Jqv0S", + "colab": {} + }, + "source": [ + "# What you past here should look like:\n", + "#!git clone https://github.com/ origin/master\n", + "Updating 21f393b..012c415\n", + "Fast-forward\n", + " Labs/Lab-1/Copy_of_Lab_1.ipynb | 1138 \u001b[32m++++++++++++++++++++++++++++++++++++++++\u001b[m\n", + " 1 file changed, 1138 insertions(+)\n", + " create mode 100644 Labs/Lab-1/Copy_of_Lab_1.ipynb\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "u9RAhs5b4vXY" + }, + "source": [ + "You should be setup now.\n", + "\n", + "## Make your for Private\n", + "\n", + "As a final step, go back to your fork in GitHub and click the \"gear\" icon to change the settings. Select \"Options\" on the left and scroll all the way down. Then click on \"Make Private\" to make your repository private. \n", + "\n", + "Next select the collaborators on the left and add your Professor and TA as collaborators. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "i1q1wv0IqqBL", + "colab_type": "text" + }, + "source": [ + "## Working on and Submitting Labs\n", + "\n", + "As mentioned in class, you are welcome to not use Google Colab and instead install and use your own instance of Jupyter to work on the labs.\n", + "\n", + "No matter where you do you work, you will submit your work into your fork of the class repository in GitHub. \n", + "\n", + "### Updating your fork\n", + "\n", + "The class repository will be updated several times a week. But your fork will not be updated, unless you do so explicitly. There are two ways for you to update your fork:\n", + "\n", + "1. Use GitHub's web interface to make a pull request from the course base to your fork.\n", + " * Goto your fork in GitHub.\n", + " * Press \"New Pull Request\"\n", + " * You should see option to select base/head repository that allows you to select \"afarbin/Data1401-Spring-2020\" as the base. If not press \"compare accross forks\".\n", + " * Make sure you select your fork as the head.\n", + " * Press \"Create a pull request\".\n", + " * Press \"Merge pull request\".\n", + " * Press \"Confirm pull\".\n", + "\n", + "2. Go to your clone of your fork in Google Drive (or local on your computer) that setup above and do a `git pull`. (Advanced)\n", + "\n", + "### Working on your labs\n", + "\n", + "If you are working in Google Colab, you should immediately save a copy of you labs into your Google Drive as soon as you start working, and save frequently so you don't loose your work. These copies of the labs will appear in drive/My Drive/Colab Notebooks. \n", + "\n", + "### Submitting your labs\n", + "\n", + "Once you are done with a lab and are ready to submit, you have several options:\n", + "\n", + "1. You can download the lab to your local computer and them commit to your GitHub fork via GitHub's web interface. \n", + "\n", + " * Download by selecting \"Download .ipynb\" from the file menu.\n", + " * Appropriately rename the downloaded file (for example Lab-1-Solutions.ipynb).\n", + " * On github, navigate to the directory for the specific lab.\n", + " * Click on upload and upload your solutions.\n", + "\n", + "2. (Advanced) You can copy the lab into your fork and commit/push using the command-line. Here's how:\n", + "\n", + " * Using \"cd\" command navigate to the clone of your fork in Google Drive (or local) and do `git remote -v` to verify that things are correctly setup.\n", + "\n", + " * If you are working on Google Colab, your copy of lab with your solutions is stored in contents/drive/My Drive/Colab Notebooks. Locate the your lab 1 notebook and copy and rename it into the same directory in your fork. \n", + "\n", + "For example: (Note we are using the full paths here just to make sure everything works... but if you are already in the fork directory, you don't need the full path everywhere)." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "CtPQXoQMdBGg", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!mkdir /content/drive/My\\ Drive/Data-1401-Repo/DATA1401-Spring-2020/Labs/Lab-2/\n", + "!cp /content/drive/My\\ Drive/Colab\\ Notebooks/Copy\\ of\\ Lab-2.ipynb /content/drive/My\\ Drive/Data-1401-Repo/DATA1401-Spring-2020/Labs/Lab-2/Lab-2-Solution.ipynb" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b04FrL7sdBGr", + "colab_type": "text" + }, + "source": [ + "The reason we are renaming the file is due to a complication that you may experience when pulling updates into your fork. If a file was updated after your last pull and modifications, your modifications will likely cause a merge conflict, which can be a headache to resolve. Creating a new file side-steps this problem.\n", + "\n", + "Now that you have a new file in your fork, add the file into local repository:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2o9JmQ1QdBGs", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#!git add /content/drive/My\\ Drive/Data-1401-Repo/DATA1401-Spring-2020/Labs/Lab-2/Lab-2-Solution.ipynb\n", + "!git add Labs/Lab-2/Lab-2-Solution.ipynb" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "HX4xOctmdBG0", + "colab_type": "text" + }, + "source": [ + "You only need to add a file once. Next, commit this file to your local copy of the repository. If this is the first time you are doing a commit, you will have to tell git your github username." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Tn9jf5VXdBG1", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Uncomment and modify lines below if needed\n", + "!git config --global user.email \"sammyson79@gmail.com\"\n", + "!git config --global user.name \"Samson Nguyen\"\n", + "#!git commit -a -m \"My Lab 2 Solutions\"" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "JfKXTlv1dBG5", + "colab_type": "text" + }, + "source": [ + "You are required to provide a text message when commiting files, and the `-m` option is the nicest way to do it. If you do not supply a message, you will find yourself in a text editor (most likely vi) which is difficult to use and forced to enter a message.\n", + "\n", + "You will need to commit your changes every time you wish to submit any changes. So if you keep working or come back to a lab, make sure you commit your changes.\n", + "\n", + "Now that you committed your changes, you will need to push these changes to the fork of the package in your github account:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "L7UZOLYAdBG6", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "220f9a52-9653-4398-aea7-dbebf928078e" + }, + "source": [ + "!git push" + ], + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "text": [ + "fatal: could not read Username for 'https://github.com': No such device or address\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3dI_D9PAdBG-", + "colab_type": "text" + }, + "source": [ + "You will likely need to supply you git username and password.\n", + "\n", + "Your lab is now available for grading. Remember that unless you commit and push your work, it will not be seen.\n", + "\n", + "From now on, use this procedure to submit your solutions to labs, including the remainder of this lab. \n", + "\n", + "You can work in your Solutions directory if you like. But note that it may be a good practice to use the \"File\" menu to duplicate and remain labs when you first start. Besides letting you avoid having to do the copy later, you will have a copy of the original notebook, in case you delete something and can pull updates, in case of bug fixes." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q-gMWiE4dBG_", + "colab_type": "text" + }, + "source": [ + "## Python Programming\n", + "\n", + "In the remainder of this lab you will practice python by solving some simple exercises. \n", + "\n", + "*Exercise 1:* Write 2 functions `even(x)` and `odd(x)` that take an integer and returns True if the input is even or odd, otherwise returns False. Use cell below for your solution. Use the subsequent cell to demonstrate that your solution works. Feel free to add additional cell as needed using the \"+\" button on the button bar above. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "jwN5jff1dBG_", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def even(x):\n", + " return x & 1 == 0\n", + "def odd(x):\n", + " return x & 1 == 1" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "xNJAcodhdBHB", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + }, + "outputId": "0ba4291e-08cc-4bf4-b430-65e995ae24ae" + }, + "source": [ + "# Test your solution here\n", + "for i in range(10):\n", + " print(i, even(i), odd(i))" + ], + "execution_count": 37, + "outputs": [ + { + "output_type": "stream", + "text": [ + "0 True False\n", + "1 False True\n", + "2 True False\n", + "3 False True\n", + "4 True False\n", + "5 False True\n", + "6 True False\n", + "7 False True\n", + "8 True False\n", + "9 False True\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "KL_pyzG8dBHD", + "colab_type": "text" + }, + "source": [ + "*Exercise 2:* Write a function that takes a list of numbers as input and returns a list of the subset of elements that are less that 10. Test your solution." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "g8nt0wnldBHE", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def less_than_ten(nums):\n", + " return [num for num in nums if num < 10]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "__HTUWA1dBHH", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "73bb8c1d-8fa3-49a5-f4a3-5667c44e3667" + }, + "source": [ + "# Test your solution here\n", + "test_nums = [x**2 for x in range(11)]\n", + "print(test_nums)\n", + "print(less_than_ten(test_nums))" + ], + "execution_count": 86, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n", + "[0, 1, 4, 9]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "T0cx91JudBHK", + "colab_type": "text" + }, + "source": [ + "*Exercise 3:* Write a function that takes a number `x_max` as input and returns a function that performs the same task as exercise 2, but for `x_max` instead of 10." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PqummMcmdBHK", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def f(x_max):\n", + " def less_than_x_max(nums):\n", + " return [num for num in nums if num < x_max]\n", + " return less_than_x_max" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "evRYemjXdBHN", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "2ea5ad48-9758-424c-eab6-b4118a279947" + }, + "source": [ + "# Test your solution here\n", + "less_than_fifty = f(50)\n", + "print(test_nums)\n", + "print(less_than_fifty(test_nums))" + ], + "execution_count": 88, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]\n", + "[0, 1, 4, 9, 16, 25, 36, 49]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "h0I8M27LdBHP", + "colab_type": "text" + }, + "source": [ + "*Exercise 4:* Write a function that takes an interger as input and returns a list of all divisors of that number." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "k6GUpDyrdBHP", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def divisors(int_x):\n", + " return [n for n in range(1, int_x + 1) if int_x % n == 0]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "YDvRmft-dBHR", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + }, + "outputId": "e945c93e-237c-438c-ea8a-ec7e1e03281a" + }, + "source": [ + "# Test your solution here\n", + "print(*zip(test_nums,[divisors(num) for num in test_nums]), sep=\"\\n\")" + ], + "execution_count": 102, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(0, [])\n", + "(1, [1])\n", + "(4, [1, 2, 4])\n", + "(9, [1, 3, 9])\n", + "(16, [1, 2, 4, 8, 16])\n", + "(25, [1, 5, 25])\n", + "(36, [1, 2, 3, 4, 6, 9, 12, 18, 36])\n", + "(49, [1, 7, 49])\n", + "(64, [1, 2, 4, 8, 16, 32, 64])\n", + "(81, [1, 3, 9, 27, 81])\n", + "(100, [1, 2, 4, 5, 10, 20, 25, 50, 100])\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IOWnLMvxdBHT", + "colab_type": "text" + }, + "source": [ + "*Exercise 5:* Write a function that takes 2 lists as input and returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tR31bnTDdBHT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def compare_lists(list_1, list_2):\n", + " return [element for element in list_1 if element in list_2]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IJDf6ebYdBHV", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "outputId": "e243c50d-74ed-4991-82d5-b3c72ddb2136" + }, + "source": [ + "# Test your solution here\n", + "test_list_1 = [i for i in range(15)]\n", + "test_list_2 = [2 * i for i in range(15)]\n", + "print(test_list_1)\n", + "print(test_list_2)\n", + "print(compare_lists(test_list_1, test_list_2))" + ], + "execution_count": 105, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]\n", + "[0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28]\n", + "[0, 2, 4, 6, 8, 10, 12, 14]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3vA7M9pldBHX", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* Write a function that reads takes a string and returns `True` if the string is a palindrome. (A palindrome is a string that reads the same forwards and backwards.)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ncyMDzp6dBHX", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def is_palindrome(str_x):\n", + " return str_x == str_x[::-1]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "v5cmVQ6MdBHZ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "4ceb0434-48e0-4444-f460-596ea81e8bf0" + }, + "source": [ + "# Test your solution here\n", + "print(is_palindrome(\"tacocat\"))\n", + "print(is_palindrome(\"wasssup\"))" + ], + "execution_count": 133, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True\n", + "False\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fT35xwandBHc", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Write a Rock-Paper-Scissors game function, that takes 2 strings, the inputs of player 1 and player 2, and output 1 or 2 corresponding to which player wins, or 0 if draw.\n", + "\n", + "Implement a Rock-Paper-Scissors game by soliciting input from 2 players, testing with this function, and repeating if there is a draw.\n", + "\n", + "Remember the rules:\n", + "\n", + "* Rock beats scissors\n", + "* Scissors beats paper\n", + "* Paper beats rock" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "U1_HxxaWdBHd", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def rock_paper_scissors():\n", + " p1 = input(\"Player 1, R, P, or S? \").upper()\n", + " p2 = input(\"Player 2, R, P, or S? \").upper()\n", + " if p1 == p2:\n", + " print(\"It's a draw!\")\n", + " return 0\n", + " else:\n", + " p1_wins = {(\"R\", \"S\"), (\"P\", \"R\"), (\"S\", \"P\")}\n", + " if (p1, p2) in p1_wins:\n", + " print(\"Player 1 wins!!!\")\n", + " return 1\n", + " else:\n", + " print(\"Player 2 wins!!!\")\n", + " return 2\n", + " " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "ooR2ldZBdBHf", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 221 + }, + "outputId": "e051d334-0b0e-4b62-d607-7bf0fee9f972" + }, + "source": [ + "# Test your solution here\n", + "we_need_to_keep_going = 0\n", + "while(we_need_to_keep_going == 0):\n", + " we_need_to_keep_going = rock_paper_scissors()" + ], + "execution_count": 145, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Player 1, R, P, or S? R\n", + "Player 2, R, P, or S? R\n", + "It's a draw!\n", + "Player 1, R, P, or S? P\n", + "Player 2, R, P, or S? P\n", + "It's a draw!\n", + "Player 1, R, P, or S? S\n", + "Player 2, R, P, or S? S\n", + "It's a draw!\n", + "Player 1, R, P, or S? R\n", + "Player 2, R, P, or S? P\n", + "Player 2 wins!!!\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dJQzXNKzdBHh", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Write a function that takes a integer `n` as input and \n", + "outputs a list of the first `n` Fibonnaci numbers.\n", + "\n", + "The Fibonnaci seqence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, …)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "G_4ooRXTdBHh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def fib(n):\n", + " if n == 0:\n", + " return []\n", + " elif n == 1:\n", + " return [0]\n", + " nums = [0,1]\n", + " while len(nums) < n:\n", + " nums.append(nums[-2] + nums[-1])\n", + " return nums" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "rzK5FskJdBHj", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 207 + }, + "outputId": "ae170b55-6566-47a4-dd13-fe7a3391a898" + }, + "source": [ + "# Test your solution here\n", + "print(*[(fibs**2, fib(fibs**2)) for fibs in range(10)], sep=\"\\n\")" + ], + "execution_count": 155, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(0, [])\n", + "(1, [0])\n", + "(4, [0, 1, 1, 2])\n", + "(9, [0, 1, 1, 2, 3, 5, 8, 13, 21])\n", + "(16, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610])\n", + "(25, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368])\n", + "(36, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465])\n", + "(49, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976])\n", + "(64, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842])\n", + "(81, [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, 17711, 28657, 46368, 75025, 121393, 196418, 317811, 514229, 832040, 1346269, 2178309, 3524578, 5702887, 9227465, 14930352, 24157817, 39088169, 63245986, 102334155, 165580141, 267914296, 433494437, 701408733, 1134903170, 1836311903, 2971215073, 4807526976, 7778742049, 12586269025, 20365011074, 32951280099, 53316291173, 86267571272, 139583862445, 225851433717, 365435296162, 591286729879, 956722026041, 1548008755920, 2504730781961, 4052739537881, 6557470319842, 10610209857723, 17167680177565, 27777890035288, 44945570212853, 72723460248141, 117669030460994, 190392490709135, 308061521170129, 498454011879264, 806515533049393, 1304969544928657, 2111485077978050, 3416454622906707, 5527939700884757, 8944394323791464, 14472334024676221, 23416728348467685])\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q6c_AskadBHl", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Write a function that takes a string of consisting of several words and returns a string that reverses the order of the words.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "aJdXX6FHdBHl", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def reverse_sentence(sentence):\n", + " words = sentence.split()[::-1]\n", + " reversed_sentence = \"\"\n", + " for word in words:\n", + " reversed_sentence += word + \" \"\n", + " return reversed_sentence" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nQyhnLZ_dBHn", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "79995de8-f78f-42f4-dd52-46534cea69b1" + }, + "source": [ + "# Test your solution here\n", + "test_sentence = \"The quick brown fox jumped over the lazy dog\"\n", + "print(reverse_sentence(test_sentence))" + ], + "execution_count": 182, + "outputs": [ + { + "output_type": "stream", + "text": [ + "dog lazy the over jumped fox brown quick The \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NFSmRaSydBHq", + "colab_type": "text" + }, + "source": [ + "*Exercise 10:* Write a guessing game program that will repeatedly guess a number that the users picks, with the user indicating higher or lower, until it correctly guesses the number." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Ie2E1JzCdBHr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def guess():\n", + " input(\"Pick a number between 0 and 100 and I'll try to guess it.\\nPress \\\"enter\\\" when ready.\")\n", + " numbers = range(0, 101)\n", + " while True:\n", + " print(\"My guess is... \" + str(numbers[len(numbers)//2]) + \"!\")\n", + " if len(numbers) == 1:\n", + " print(\"Now I HAVE to be right! There's nothing else to guess!\")\n", + " hol = input(\"Was I right? Or did I guess too high or low (r/h/l)? \")\n", + " if hol == \"r\":\n", + " print(\"Woohoo! The number you picked was \" + str(numbers[len(numbers)//2]))\n", + " return\n", + " elif hol == \"h\" and len(numbers) > 1:\n", + " numbers = numbers[:len(numbers)//2]\n", + " elif hol == \"l\" and len(numbers) > 1:\n", + " numbers = numbers[len(numbers)//2 + 1:]\n", + " " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "6T8YdWSMdBHs", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 323 + }, + "outputId": "ab7dcf1e-e752-4b6b-bd1f-37e930c0a890" + }, + "source": [ + "# Test your solution here\n", + "guess()" + ], + "execution_count": 193, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Pick a number between 0 and 100 and I'll try to guess it.\n", + "Press \"enter\" when ready.\n", + "My guess is... 50!\n", + "Was I right? Or did I guess too high or low (r/h/l)? h\n", + "My guess is... 25!\n", + "Was I right? Or did I guess too high or low (r/h/l)? h\n", + "My guess is... 12!\n", + "Was I right? Or did I guess too high or low (r/h/l)? l\n", + "My guess is... 19!\n", + "Was I right? Or did I guess too high or low (r/h/l)? h\n", + "My guess is... 16!\n", + "Was I right? Or did I guess too high or low (r/h/l)? h\n", + "My guess is... 14!\n", + "Was I right? Or did I guess too high or low (r/h/l)? h\n", + "My guess is... 13!\n", + "Now I HAVE to be right! There's nothing else to guess!\n", + "Was I right? Or did I guess too high or low (r/h/l)? r\n", + "Woohoo! The number you picked was 13\n" + ], + "name": "stdout" + } + ] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-3/Copy_of_Lab_3.ipynb b/Labs/Lab-3/Copy_of_Lab_3.ipynb new file mode 100644 index 0000000..02f9db2 --- /dev/null +++ b/Labs/Lab-3/Copy_of_Lab_3.ipynb @@ -0,0 +1,970 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-3.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "YuaEkVael6wx", + "colab_type": "text" + }, + "source": [ + "# Lab 3- Tic Tac Toe\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-3/Lab-3.ipynb)\n", + "\n", + "In this lab your will build a n x n Tic Tac Toe game. As you do the exercises, make sure your solutions work for any size Tic Tac Toe game. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7rZcHrSEl6w2", + "colab_type": "text" + }, + "source": [ + "*Exercise 1:* Write a function that creates an n by n matrix (of list of lists) which will represent the state of a Tie Tac Toe game. Let 0, 1, and 2 represent empty, \"X\", or \"O\".\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "qCG0daLAl6w4", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "empty = 0\n", + "player_1 = 1\n", + "player_2 = 2\n", + "players = {0: \" \",\n", + " 1: \"X\",\n", + " 2: \"O\"}\n", + "\n", + "\n", + "def make_game_board(n=3):\n", + " return [[empty] * n for i in range(n)]\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "xLZxreLTl6w_", + "colab_type": "code", + "outputId": "fe454a38-9d17-4bb6-bb49-4ee1b2c8f4a6", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "print(make_game_board())" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "1Gpsh1YMl6xD", + "colab_type": "text" + }, + "source": [ + "*Exercise 2:* Write a function that takes a `n` by `n` matrix representing a tic-tac-toe game, and returns -1, 0, 1, or 2 indicating the game is incomplete, the game is a draw, player 1 has won, or player 2 has one, respectively. Here are some example inputs you can use to test your code:" + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "4edyIxvNl6xF", + "colab_type": "code", + "colab": {} + }, + "source": [ + "winner_is_2 = [[2, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "winner_is_1 = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "winner_is_also_1 = [[0, 1, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "no_winner = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 2]]\n", + "\n", + "also_no_winner = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 0]]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "pMveSEzVl6xN", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def check_game_finished(board):\n", + " board_wins = [row for row in board] # rows\n", + " board_wins += [list(row) for row in zip(*board)] # columns\n", + " board_wins += [[board[i][i] for i in range(len(board))]] # right down diagonal\n", + " board_wins += [[board[len(board) - 1 - i][i] for i in range(len(board))]] # left down diagonal\n", + " if [1] * len(board) in board_wins:\n", + " return 1\n", + " elif [2] * len(board) in board_wins:\n", + " return 2\n", + " elif True in [board[i][j] == 0 for i in range(len(board)) for j in range(len(board))]:\n", + " return -1\n", + " else:\n", + " return 0\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "jFvUimXMl6xS", + "colab_type": "code", + "outputId": "ab2ed326-4253-42dc-d3ea-72e57487da20", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "# Test your solution here\n", + "print(check_game_finished(winner_is_2))\n", + "print(check_game_finished(winner_is_1))\n", + "print(check_game_finished(winner_is_also_1))\n", + "print(check_game_finished(no_winner))\n", + "print(check_game_finished(also_no_winner))" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "2\n", + "1\n", + "1\n", + "-1\n", + "-1\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "KJ67s2CZl6xb", + "colab_type": "text" + }, + "source": [ + "*Exercise 3:* Write a function that takes 2 integers `n` and `m` as input and draws a `n` by `m` game board. For example the following is a 3x3 board:\n", + "```\n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " ```" + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "u3NzwB4Jl6xd", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def draw_game_board(n, m):\n", + " for row in range(n):\n", + " line_1 = \"\"\n", + " line_2 = \"\"\n", + " for col in range(m):\n", + " line_1 += \" ---\"\n", + " line_2 += \"| \"\n", + " line_2 += \"|\"\n", + " print(line_1)\n", + " print(line_2)\n", + " bottom = \"\"\n", + " for col in range(m):\n", + " bottom += \" ---\"\n", + " print(bottom)\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "wrLb0jtcl6xi", + "colab_type": "code", + "outputId": "11643445-b2a6-4274-b9d4-983254111bef", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 374 + } + }, + "source": [ + "# Test your solution here\n", + "draw_game_board(3, 3)\n", + "draw_game_board(2, 4)\n", + "draw_game_board(4, 5)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " --- --- ---\n", + "| | | |\n", + " --- --- ---\n", + "| | | |\n", + " --- --- ---\n", + "| | | |\n", + " --- --- ---\n", + " --- --- --- ---\n", + "| | | | |\n", + " --- --- --- ---\n", + "| | | | |\n", + " --- --- --- ---\n", + " --- --- --- --- ---\n", + "| | | | | |\n", + " --- --- --- --- ---\n", + "| | | | | |\n", + " --- --- --- --- ---\n", + "| | | | | |\n", + " --- --- --- --- ---\n", + "| | | | | |\n", + " --- --- --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "nUAE_QUal6xq", + "colab_type": "text" + }, + "source": [ + "*Exercise 4:* Modify exercise 3, so that it takes a matrix of the form from exercise 2 and draws a tic-tac-tie board with \"X\"s and \"O\"s. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "fGddb0gIl6xs", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def draw_game_board(board):\n", + " for row in board:\n", + " line_1 = \"\"\n", + " line_2 = \"\"\n", + " for col in row:\n", + " line_1 += \" ---\"\n", + " line_2 += \"| \" + players[col] + \" \"\n", + " line_2 += \"|\"\n", + " print(line_1)\n", + " print(line_2)\n", + " bottom = \"\"\n", + " for col in board:\n", + " bottom += \" ---\"\n", + " print(bottom)\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "DNm_lodnl6xy", + "colab_type": "code", + "outputId": "f39170d3-4772-4aa4-c143-57c5559e8ad7", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 612 + } + }, + "source": [ + "# Test your solution here\n", + "draw_game_board(winner_is_1)\n", + "draw_game_board(winner_is_2)\n", + "draw_game_board(winner_is_also_1)\n", + "draw_game_board(no_winner)\n", + "draw_game_board(also_no_winner)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| O | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| | X | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | O |\n", + " --- --- ---\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "ehxOT9Ehl6x4", + "colab_type": "text" + }, + "source": [ + "*Exercise 5:* Write a function that takes a game board, player number, and `(x,y)` coordinates and places \"X\" or \"O\" in the correct location of the game board. Make sure that you only allow filling previously empty locations. Return `True` or `False` to indicate successful placement of \"X\" or \"O\"." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "MfTefPdll6x5", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def _move(board, player, coordinates):\n", + " x, y = coordinates\n", + " if board[x][y] == 0:\n", + " board[x][y] = player\n", + " return True\n", + " else:\n", + " return False" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "wk7OoaNcl6yA", + "colab_type": "code", + "outputId": "fac2d9fd-42a5-43ce-a297-c62787bc7674", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 136 + } + }, + "source": [ + "# Test your solution here\n", + "test_board = make_game_board()\n", + "_move(test_board, 1, (1, 1))\n", + "_move(test_board, 2, (2, 0))\n", + "draw_game_board(test_board)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " --- --- ---\n", + "| | | |\n", + " --- --- ---\n", + "| | X | |\n", + " --- --- ---\n", + "| O | | |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "OXmrF3VBl6yG", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* Modify Exercise 4 to show column and row labels so that players can specify location using \"A2\" or \"C1\"." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5luh37Ovl6yI", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "alphabet = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\n", + "def draw_game_board(board):\n", + " top = \" \"\n", + " for col in range(1, len(board) + 1):\n", + " top += \" \" + str(col) + \" \"\n", + " print(top)\n", + " r = 0\n", + " for row in board:\n", + " line_1 = \" \"\n", + " line_2 = alphabet[r] + \" \"\n", + " r += 1\n", + " for col in row:\n", + " line_1 += \" ---\"\n", + " line_2 += \"| \" + players[col] + \" \"\n", + " line_2 += \"|\"\n", + " print(line_1)\n", + " print(line_2)\n", + " print(\" \" + \" ---\" * len(board))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "Zo6zTO_ll6yO", + "colab_type": "code", + "outputId": "5935d556-6d31-4fc0-cfab-c4e741625ea5", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 697 + } + }, + "source": [ + "# Test your solution here\n", + "draw_game_board(winner_is_1)\n", + "draw_game_board(winner_is_2)\n", + "draw_game_board(winner_is_also_1)\n", + "draw_game_board(no_winner)\n", + "draw_game_board(also_no_winner)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | O | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | | X | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | O |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "rlfmfYRWl6yT", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Write a function that takes a board, player number, and location specified as in exercise 6 and then calls exercise 5 to correctly modify the board. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "R9Lngg8wl6yW", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def move(board, player, location):\n", + " row = alphabet.find(location[0])\n", + " col = int(location[1:]) - 1\n", + " if board[row][col] == 0:\n", + " _move(board, player, (row, col))\n", + " return True\n", + " else:\n", + " print(\"Cannot put \" + players[player] + \" at location \" + location)\n", + " return False" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "on6HRvX7l6ya", + "colab_type": "code", + "outputId": "5e9f3a17-275d-4c55-cd81-9e198ccb05dd", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 289 + } + }, + "source": [ + "# Test your solution here\n", + "move(no_winner, 1, \"A3\")\n", + "draw_game_board(no_winner)\n", + "move(also_no_winner, 1, \"C3\")\n", + "draw_game_board(also_no_winner)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | X |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | O |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "spCblEgSl6yf", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Write a function is called with a board and player number, takes input from the player using python's `input`, and modifies the board using your function from exercise 7. Note that you should keep asking for input until you have gotten a valid input that results in a valid move." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "R2_KLmnhl6yi", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def player_move(board, player):\n", + " location = \"A1\"\n", + " while True:\n", + " draw_game_board(board)\n", + " location = input(\"Place \" + players[player] + \" at: \").upper()\n", + " if location[0] in alphabet and alphabet.find(location[0]) < len(board) and location[1:].isnumeric() and 0 < int(location[1:]) <= len(board) <= 26:\n", + " break\n", + " else:\n", + " print(\"Invalid location. Try again.\")\n", + " if move(board, player, location):\n", + " return True\n", + " else:\n", + " return player_move(board, player)\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "5klPGJNVl6yp", + "colab_type": "code", + "outputId": "031bd46e-7997-43e3-e391-7f23d78dd946", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 595 + } + }, + "source": [ + "# Test your solution here\n", + "player_move(no_winner, 1)\n", + "draw_game_board(no_winner)\n", + "player_move(also_no_winner, 2)\n", + "draw_game_board(also_no_winner)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | X |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | O |\n", + " --- --- ---\n", + "Place X at: b3\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | X |\n", + " --- --- ---\n", + "B | O | X | X |\n", + " --- --- ---\n", + "C | O | X | O |\n", + " --- --- ---\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n", + "Place O at: a3\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | O |\n", + " --- --- ---\n", + "B | O | X | |\n", + " --- --- ---\n", + "C | O | X | X |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "RpFgUbL-l6yv", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Use all of the previous exercises to implement a full tic-tac-toe game, where an appropriate board is drawn, 2 players are repeatedly asked for a location coordinates of where they wish to place a mark, and the game status is checked until a player wins or a draw occurs." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "cq9kSyn3l6yw", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def tic_tac_toe(n=3):\n", + " board = make_game_board(n)\n", + " current_player = True\n", + " while check_game_finished(board) == -1:\n", + " if current_player:\n", + " player_move(board, 1)\n", + " else:\n", + " player_move(board, 2)\n", + " current_player = not current_player\n", + " result = check_game_finished(board)\n", + " draw_game_board(board)\n", + " print(\"It's a draw!\" if result == 0 else (\"Player 1 wins!\" if result == 1 else \"Player 2 wins!\"))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "aBSvAvKWl6yz", + "colab_type": "code", + "outputId": "868b6418-dbad-4a09-dd92-46829dcc78be", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 765 + } + }, + "source": [ + "# Test your solution here\n", + "tic_tac_toe()" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- ---\n", + "A | | | |\n", + " --- --- ---\n", + "B | | | |\n", + " --- --- ---\n", + "C | | | |\n", + " --- --- ---\n", + "Place X at: a1\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | | |\n", + " --- --- ---\n", + "B | | | |\n", + " --- --- ---\n", + "C | | | |\n", + " --- --- ---\n", + "Place O at: a2\n", + " 1 2 3 \n", + " --- --- ---\n", + "A | X | O | |\n", + " --- --- ---\n", + "B | | | |\n", + " --- --- ---\n", + "C | | | |\n", + " --- --- ---\n", + "Place X at: \n" + ], + "name": "stdout" + }, + { + "output_type": "error", + "ename": "IndexError", + "evalue": "ignored", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mIndexError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtic_tac_toe\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m", + "\u001b[0;32m\u001b[0m in \u001b[0;36mtic_tac_toe\u001b[0;34m(n)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0;32mwhile\u001b[0m \u001b[0mcheck_game_finished\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mcurrent_player\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0mplayer_move\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0mplayer_move\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mplayer_move\u001b[0;34m(board, player)\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mdraw_game_board\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0mlocation\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0minput\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"Place \"\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0mplayers\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mplayer\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;34m+\u001b[0m \u001b[0;34m\" at: \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mupper\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 6\u001b[0;31m \u001b[0;32mif\u001b[0m \u001b[0mlocation\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m \u001b[0;32min\u001b[0m \u001b[0malphabet\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0malphabet\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfind\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0mlocation\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0misnumeric\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;32mand\u001b[0m \u001b[0;36m0\u001b[0m \u001b[0;34m<\u001b[0m \u001b[0mint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mlocation\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0mlen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mboard\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m<=\u001b[0m \u001b[0;36m26\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 7\u001b[0m \u001b[0;32mbreak\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 8\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mIndexError\u001b[0m: string index out of range" + ] + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "_ecYRctEl6y3", + "colab_type": "text" + }, + "source": [ + "*Exercise 10:* Test that your game works for 5x5 Tic Tac Toe. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "SOV5nKS4l6y5", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here\n", + "tic_tac_toe(5)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "6W-bTUC9l6y8", + "colab_type": "text" + }, + "source": [ + "*Exercise 11: (Extra Credit)* Develop a version of the game where one player is the computer. Note that you don't need to do an extensive seach for the best move. You can have the computer simply protect against loosing and otherwise try to win with straight or diagonal patterns." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "TRfUlsytl6y-", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "\n", + "\n", + "def tic_tac_toe(n=3):\n", + " board = make_game_board(n)\n", + " current_player = True\n", + " while check_game_finished(board) == -1:\n", + " if current_player:\n", + " player_move(board, 1)\n", + " else:\n", + " player_move(board, 2)\n", + " current_player = not current_player\n", + " result = check_game_finished(board)\n", + " draw_game_board(board)\n", + " print(\"It's a draw!\" if result == 0 else (\"Player 1 wins!\" if result == 1 else \"Player 2 wins!\"))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "EdxBYXsLl6zD", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-3/TicTacToe.py b/Labs/Lab-3/TicTacToe.py new file mode 100644 index 0000000..bfb2fde --- /dev/null +++ b/Labs/Lab-3/TicTacToe.py @@ -0,0 +1,106 @@ +# Write you solution here +empty = 0 +player_1 = 1 +player_2 = 2 +players = {0: " ", + 1: "X", + 2: "O"} + + +def make_game_board(n=3): + return [[empty] * n for i in range(n)] + + +# return 1 if p1 wins +# return 2 if p2 wins +# return 0 if game not finished +# return -1 if draw +def check_game_finished(board): + board_wins = [row for row in board] + board_wins += [list(row) for row in zip(*board)] + board_wins += [[board[i][i] for i in range(len(board))]] + board_wins += [[board[len(board) - 1 - i][i] for i in range(len(board))]] + if [1] * len(board) in board_wins: + return 1 + elif [2] * len(board) in board_wins: + return 2 + elif True in [board[i][j] == 0 for i in range(len(board)) for j in range(len(board))]: + return 0 + else: + return -1 + + +alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" + + +def draw_game_board(board): + top = " " + for col in range(1, len(board) + 1): + top += " " + str(col) + " " + print(top) + r = 0 + for row in board: + line_1 = " " + line_2 = alphabet[r] + " " + r += 1 + for col in row: + line_1 += " ---" + line_2 += "| " + players[col] + " " + line_2 += "|" + print(line_1) + print(line_2) + print(" " + " ---" * len(board)) + + +def _move(board, player, coordinates): + x, y = coordinates + if board[x][y] == 0: + board[x][y] = player + return True + else: + return False + + +def move(board, player, location): + row = alphabet.find(location[0]) + col = int(location[1:]) - 1 + if board[row][col] == 0: + _move(board, player, (row, col)) + return True + else: + print("Cannot put " + players[player] + " at location " + location) + return False + + +def player_move(board, player): + location = "A1" + while True: + draw_game_board(board) + location = input("Place " + players[player] + " at: ").upper() + if location[0] in alphabet and alphabet.find(location[0]) < len(board) and location[1:].isnumeric() and 0 < int( + location[1:]) <= len(board) <= 26: + break + else: + print("Invalid location. Try again.") + if move(board, player, location): + return True + else: + return player_move(board, player) + + +def tic_tac_toe(): + while True: + board = make_game_board() + current_player = True + while check_game_finished(board) == 0: + if current_player: + player_move(board, 1) + else: + player_move(board, 2) + current_player = not current_player + result = check_game_finished(board) + draw_game_board(board) + print("It's a draw!" if result == -1 else ("Player 1 wins!" if result == 1 else "Player 2 wins!")) + + +tic_tac_toe() diff --git a/Labs/Lab-4/Copy_of_Lab_4.ipynb b/Labs/Lab-4/Copy_of_Lab_4.ipynb new file mode 100644 index 0000000..48b9607 --- /dev/null +++ b/Labs/Lab-4/Copy_of_Lab_4.ipynb @@ -0,0 +1,1082 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "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.1" + }, + "colab": { + "name": "Copy of Lab-4.ipynb", + "provenance": [], + "collapsed_sections": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "NoBj18wB_1fa", + "colab_type": "text" + }, + "source": [ + "## Lab 4\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-4/Lab-4.ipynb)\n", + "\n", + "In this lab we will become familiar with distributions, histograms, and functional programming. \n", + "\n", + "\n", + "### Uniform Distribution\n", + "Lets start with generating some fake random data. You can get a random number between 0 and 1 using the python random module as follow:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "TmrUVAv1_1ff", + "colab_type": "code", + "outputId": "055500e9-f47c-49e2-fcad-e9430e15fecd", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "import random\n", + "x=random.random()\n", + "print(\"The Value of x is\", x)" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "The Value of x is 0.32871666542362765\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NtxsuHTs_1fw", + "colab_type": "text" + }, + "source": [ + "Everytime you call random, you will get a new number.\n", + "\n", + "*Exercise 1:* Using random, write a function `generate_uniform(N, mymin, mymax)`, that returns a python list containing N random numbers between specified minimum and maximum value. Note that you may want to quickly work out on paper how to turn numbers between 0 and 1 to between other values. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Z9GzQB02_1fy", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def generate_uniform(N,x_min,x_max):\n", + " out = []\n", + " ### BEGIN SOLUTION\n", + "\n", + " while len(out) < N:\n", + " out.append(x_min + random.random() * (x_max - x_min)) \n", + " \n", + " ### END SOLUTION\n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "eiWTH4-H_1f6", + "colab_type": "code", + "outputId": "37ef9700-6316-4947-9baa-fc05fd121af2", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "# Test your solution here\n", + "data=generate_uniform(1000,-10,10)\n", + "print(\"Data Type:\", type(data))\n", + "print(\"Data Length:\", len(data))\n", + "if len(data)>0: \n", + " print(\"Type of Data Contents:\", type(data[0]))\n", + " print(\"Data Minimum:\", min(data))\n", + " print(\"Data Maximum:\", max(data))" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Data Type: \n", + "Data Length: 1000\n", + "Type of Data Contents: \n", + "Data Minimum: -9.975816305169623\n", + "Data Maximum: 9.995291400820292\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "VOUqBefH_1gA", + "colab_type": "text" + }, + "source": [ + "*Exercise 2a:* \n", + "Write a function that computes the mean of values in a list." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6sDXXVHB_1gE", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def mean(Data):\n", + " m=0.\n", + " \n", + " ### BEGIN SOLUTION\n", + " \n", + " m = sum(Data) / len(Data)\n", + " \n", + " ### END SOLUTION\n", + " \n", + " return m" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "0Z8u7_Hq_1gK", + "colab_type": "code", + "outputId": "25a2074a-f16a-4229-c2ad-e3827754aad1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "print(\"Mean of Data:\", mean(data))" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Mean of Data: -0.03451181690297556\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "b1CWdjfM_1gR", + "colab_type": "text" + }, + "source": [ + "*Exercise 2b:* \n", + "Write a function that computes the variance of values in a list." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gfiiJxZl_1gT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def variance(Data):\n", + " m=0.\n", + " \n", + " ### BEGIN SOLUTION\n", + "\n", + " m = mean(Data)\n", + " variance = sum((x - m) ** 2 for x in Data) / len(Data)\n", + " \n", + " ### END SOLUTION\n", + " \n", + " return variance" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IbasE7ma_1gZ", + "colab_type": "code", + "outputId": "654d0f50-968d-4669-e051-e12d3905741c", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "print(\"Variance of Data:\", variance(data))" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Variance of Data: 31.635785180548243\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7qtsjJNA_1ge", + "colab_type": "text" + }, + "source": [ + "## Histogramming" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FJsWb1o9_1gf", + "colab_type": "text" + }, + "source": [ + "*Exercise 3:* Write a function that bins the data so that you can create a histogram. An example of how to implement histogramming is the following logic:\n", + "\n", + "* User inputs a list of values `x` and optionally `n_bins` which defaults to 10.\n", + "* If not supplied, find the minimum and maximum (`x_min`,`x_max`) of the values in x.\n", + "* Determine the bin size (`bin_size`) by dividing the range of the function by the number of bins.\n", + "* Create an empty list of zeros of size `n_bins`, call it `hist`.\n", + "* Loop over the values in `x`\n", + " * Loop over the values in `hist` with index `i`:\n", + " * If x is between `x_min+i*bin_size` and `x_min+i*2*bin_size`, increment `hist[i].` \n", + " * For efficiency, try to use continue to goto the next bin and data point.\n", + "* Return `hist` and the list corresponding of the bin edges (i.e. of `x_min+i*bin_size`). " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Yp85CdIF_1gh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Solution\n", + "def histogram(x,n_bins=10,x_min=None,x_max=None):\n", + " ### BEGIN SOLUTION\n", + "\n", + " if x_min == None:\n", + " x_min = min(x)\n", + " if x_max == None:\n", + " x_max = max(x)\n", + " \n", + " bin_size = (x_max - x_min) / n_bins\n", + "\n", + " hist = [0] * n_bins\n", + " bin_edges = [x_min]\n", + " for i in range(1, n_bins + 1):\n", + " bin_edges.append(x_min + i * bin_size)\n", + " for value in x:\n", + " for i in range(n_bins):\n", + " if (x_min + (i * bin_size)) <= value <= (x_min + ((i + 1) * bin_size)):\n", + " hist[i] += 1\n", + " break\n", + " \n", + " ### END SOLUTION\n", + "\n", + " return hist,bin_edges" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "CQg5EFMg_1gn", + "colab_type": "code", + "outputId": "11e0626a-665e-4487-c67d-9a915e38acef", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + } + }, + "source": [ + "# Test your solution here\n", + "h,b=histogram(data,100)\n", + "print(len(b),h)" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + "101 [8, 7, 8, 9, 10, 11, 13, 5, 15, 6, 8, 14, 11, 10, 11, 14, 7, 4, 7, 4, 15, 11, 16, 5, 11, 7, 12, 10, 11, 12, 10, 14, 17, 9, 7, 8, 7, 9, 8, 13, 7, 9, 8, 11, 13, 12, 11, 15, 15, 10, 9, 13, 8, 13, 14, 8, 16, 11, 15, 14, 6, 13, 12, 8, 5, 9, 5, 13, 7, 13, 6, 4, 11, 12, 9, 13, 11, 10, 3, 9, 16, 11, 7, 13, 9, 7, 13, 3, 8, 11, 8, 13, 13, 14, 6, 9, 5, 13, 10, 6]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "miaZ7qfS_1gs", + "colab_type": "text" + }, + "source": [ + "*Exercise 4:* Write a function that uses the histogram function in the previous exercise to create a text-based \"graph\". For example the output could look like the following:\n", + "```\n", + "[ 0, 1] : ######\n", + "[ 1, 2] : #####\n", + "[ 2, 3] : ######\n", + "[ 3, 4] : ####\n", + "[ 4, 5] : ####\n", + "[ 5, 6] : ######\n", + "[ 6, 7] : #####\n", + "[ 7, 8] : ######\n", + "[ 8, 9] : ####\n", + "[ 9, 10] : #####\n", + "```\n", + "\n", + "Where each line corresponds to a bin and the number of `#`'s are proportional to the value of the data in the bin. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ajxAao2B_1gt", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Solution\n", + "def draw_histogram(x,n_bins,x_min=None,x_max=None,character=\"#\",max_character_per_line=20):\n", + " ### BEGIN SOLUTION\n", + "\n", + " bins = []\n", + "\n", + " hist, bin_edges = histogram(x, n_bins, x_min, x_max)\n", + "\n", + " max_hist = max(hist)\n", + "\n", + " for i in range(len(bin_edges) - 1):\n", + " print(\"[\" + \"{:7.3f}\".format(bin_edges[i]) + \",\" + \"{:7.3f}\".format(bin_edges[i + 1]) + \"] : \" + (str(character) * int(hist[i] / max_hist * max_character_per_line)))\n", + " \n", + " ### END SOLUTION\n", + "\n", + " return hist,bin_edges" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "EsQxIs9U_1gy", + "colab_type": "code", + "outputId": "4ccda8ad-657b-4977-b32a-16e14dca8033", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 357 + } + }, + "source": [ + "# Test your solution here\n", + "h,b=draw_histogram(data,20)" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ -9.976, -8.977] : #############\n", + "[ -8.977, -7.979] : ###############\n", + "[ -7.979, -6.980] : ################\n", + "[ -6.980, -5.982] : ###########\n", + "[ -5.982, -4.983] : ##################\n", + "[ -4.983, -3.984] : ################\n", + "[ -3.984, -2.986] : #################\n", + "[ -2.986, -1.987] : ##############\n", + "[ -1.987, -0.989] : ###############\n", + "[ -0.989, 0.010] : ###################\n", + "[ 0.010, 1.008] : #################\n", + "[ 1.008, 2.007] : ####################\n", + "[ 2.007, 3.005] : #############\n", + "[ 3.005, 4.004] : ##############\n", + "[ 4.004, 5.003] : #############\n", + "[ 5.003, 6.001] : ##############\n", + "[ 6.001, 7.000] : #################\n", + "[ 7.000, 7.998] : #############\n", + "[ 7.998, 8.997] : ################\n", + "[ 8.997, 9.995] : #############\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "ppoPnjV4_1g3", + "colab_type": "text" + }, + "source": [ + "## Functional Programming\n", + "\n", + "*Exercise 5:* Write a function the applies a booling function (that returns true/false) to every element in data, and return a list of indices of elements where the result was true. Use this function to find the indices of entries greater than 0.5. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "HTTvnZDl_1hK", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def where(mylist,myfunc):\n", + " out= []\n", + " \n", + " ### BEGIN SOLUTION\n", + " for i in range(len(mylist)):\n", + " if myfunc(mylist[i]):\n", + " out.append(i) \n", + " \n", + " ### END SOLUTION\n", + " \n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "ZyXbNZK7_1hS", + "colab_type": "code", + "outputId": "3953bc9b-ae61-44b9-c7e9-c05e3548f65d", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + } + }, + "source": [ + "# Test your solution here\n", + "def myfunc(n):\n", + " return n > 0.5\n", + "\n", + "print(where(data, myfunc))" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[2, 3, 4, 7, 9, 13, 15, 16, 19, 22, 23, 24, 25, 27, 29, 30, 32, 33, 35, 36, 37, 38, 39, 40, 41, 42, 43, 48, 50, 53, 59, 61, 66, 69, 73, 74, 78, 82, 85, 87, 89, 93, 94, 96, 97, 98, 101, 102, 105, 106, 111, 114, 115, 116, 117, 120, 122, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 140, 144, 145, 146, 148, 149, 150, 151, 155, 158, 159, 161, 162, 163, 164, 165, 167, 170, 171, 173, 174, 175, 178, 187, 188, 189, 190, 193, 195, 196, 198, 199, 201, 202, 204, 208, 209, 210, 212, 213, 215, 220, 222, 225, 226, 227, 228, 229, 230, 235, 236, 238, 241, 245, 246, 253, 258, 259, 262, 263, 267, 268, 270, 271, 275, 277, 279, 280, 284, 290, 291, 295, 297, 298, 300, 302, 304, 306, 307, 308, 309, 312, 313, 314, 318, 319, 321, 326, 327, 329, 330, 331, 334, 337, 338, 340, 341, 343, 346, 353, 354, 355, 356, 358, 359, 361, 362, 363, 364, 365, 366, 369, 370, 371, 376, 377, 378, 379, 381, 388, 393, 396, 401, 403, 405, 406, 408, 409, 411, 412, 413, 419, 420, 423, 424, 425, 427, 429, 434, 436, 440, 442, 443, 445, 446, 447, 454, 455, 462, 463, 466, 468, 470, 471, 473, 474, 475, 478, 489, 490, 491, 494, 497, 498, 501, 502, 503, 504, 505, 506, 507, 509, 515, 518, 523, 524, 526, 528, 529, 530, 532, 533, 534, 535, 536, 537, 540, 541, 544, 545, 546, 547, 550, 551, 552, 554, 555, 559, 568, 569, 572, 574, 575, 576, 580, 581, 584, 587, 588, 589, 591, 592, 593, 598, 600, 601, 605, 613, 614, 615, 617, 620, 622, 625, 627, 628, 629, 630, 632, 633, 635, 639, 643, 648, 649, 650, 654, 655, 660, 662, 664, 665, 669, 671, 674, 675, 676, 677, 679, 680, 683, 684, 689, 690, 691, 693, 699, 701, 702, 703, 706, 707, 710, 712, 713, 718, 719, 720, 724, 728, 731, 733, 734, 736, 737, 739, 741, 743, 744, 745, 747, 748, 751, 755, 756, 769, 770, 774, 775, 777, 778, 779, 780, 783, 785, 787, 788, 790, 794, 795, 796, 797, 801, 807, 808, 810, 811, 814, 815, 816, 817, 818, 820, 821, 822, 823, 824, 826, 827, 829, 837, 838, 840, 847, 848, 851, 852, 853, 854, 855, 857, 859, 860, 863, 864, 866, 869, 870, 871, 873, 874, 876, 877, 878, 881, 882, 885, 886, 887, 889, 890, 892, 893, 895, 897, 898, 899, 900, 903, 906, 907, 910, 911, 920, 921, 922, 923, 924, 928, 932, 933, 935, 937, 942, 943, 944, 945, 950, 951, 952, 954, 956, 958, 959, 960, 961, 963, 965, 966, 972, 973, 981, 983, 984, 986, 987, 988, 989, 990, 993, 996, 997, 999]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "jt4S-KN0_1hZ", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* The inrange(mymin,mymax) function below returns a function that tests if it's input is between the specified values. Write corresponding functions that test:\n", + "* Even\n", + "* Odd\n", + "* Greater than\n", + "* Less than\n", + "* Equal\n", + "* Divisible by" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "kkchtWxy_1hb", + "colab_type": "code", + "outputId": "ff8b5e85-d03d-4652-bca9-63a18f201af4", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "def in_range(mymin,mymax):\n", + " def testrange(x):\n", + " return x=mymin\n", + " return testrange\n", + "\n", + "# Examples:\n", + "F1=in_range(0,10)\n", + "F2=in_range(10,20)\n", + "\n", + "# Test of in_range\n", + "print(F1(0), F1(1), F1(10), F1(15), F1(20))\n", + "print(F2(0), F2(1), F2(10), F2(15), F2(20))\n", + "\n", + "print(\"Number of Entries passing F1:\", len(where(data,F1)))\n", + "print(\"Number of Entries passing F2:\", len(where(data,F2)))" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True True False False False\n", + "False False True True False\n", + "Number of Entries passing F1: 496\n", + "Number of Entries passing F2: 0\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "tcReOq0v_1hf", + "colab_type": "code", + "colab": {} + }, + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "def even():\n", + " def is_even(x):\n", + " return x % 2 == 0\n", + " return is_even\n", + "\n", + "def odd():\n", + " def is_odd(x):\n", + " return x % 2 == 1\n", + " return is_odd\n", + "\n", + "def greater_than(n):\n", + " def is_greater_than(x):\n", + " return x > n\n", + " return is_greater_than\n", + "\n", + "def less_than(n):\n", + " def is_less_than(x):\n", + " return x < n\n", + " return is_less_than\n", + "\n", + "def equal_to(n):\n", + " def is_equal_to(x):\n", + " return x == n\n", + " return is_equal_to\n", + "\n", + "def divisible_by(n):\n", + " def is_divisible_by(x):\n", + " return x % n == 0\n", + " return is_divisible_by\n", + " \n", + "### END SOLUTION" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3AhyJZjf_1hj", + "colab_type": "code", + "outputId": "5f6d8f63-6e9a-4cd0-9932-31e0650a90cf", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + } + }, + "source": [ + "# Test your solution\n", + "E = even()\n", + "O = odd()\n", + "G = greater_than(0)\n", + "L = less_than(0)\n", + "EQ = equal_to(data[20])\n", + "D = divisible_by(data[50])\n", + "\n", + "print(E(2), O(2), G(2), L(2), EQ(2), D(2))\n", + "print(E(-1), O(-1), G(-1), L(-1), EQ(-1), D(-1))\n", + "\n", + "print(\"Number of Entries passing E:\", len(where(data,E)))\n", + "print(\"Number of Entries passing O:\", len(where(data,O)))\n", + "print(\"Number of Entries passing G:\", len(where(data,G)))\n", + "print(\"Number of Entries passing L:\", len(where(data,L)))\n", + "print(\"Number of Entries passing EQ:\", len(where(data,EQ)))\n", + "print(\"Number of Entries passing D:\", len(where(data,D)))" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True False True False False False\n", + "False True False True False False\n", + "Number of Entries passing E: 0\n", + "Number of Entries passing O: 0\n", + "Number of Entries passing G: 496\n", + "Number of Entries passing L: 504\n", + "Number of Entries passing EQ: 1\n", + "Number of Entries passing D: 1\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tEhLwDyH_1hq", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Repeat the previous exercise using `lambda` and the built-in python functions sum and map instead of your solution above. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VlWCyUXL_1hr", + "colab_type": "code", + "outputId": "8cc4be15-dcd4-4016-8234-2188876aa9e6", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "print(\"Number of Entries passing E:\", sum(map(lambda x: x % 2 == 0,data)))\n", + "print(\"Number of Entries passing O:\", sum(map(lambda x: x % 2 == 1, data)))\n", + "print(\"Number of Entries passing G:\", sum(map(lambda x: x > 0, data)))\n", + "print(\"Number of Entries passing L:\", sum(map(lambda x: x < 0, data)))\n", + "print(\"Number of Entries passing EQ:\", sum(map(lambda x: x == data[20], data)))\n", + "print(\"Number of Entries passing D:\", sum(map(lambda x: x % data[50] == 0, data)))\n", + "### END SOLUTION" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Number of Entries passing E: 0\n", + "Number of Entries passing O: 0\n", + "Number of Entries passing G: 496\n", + "Number of Entries passing L: 504\n", + "Number of Entries passing EQ: 1\n", + "Number of Entries passing D: 1\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7IsTjLuQ_1hz", + "colab_type": "text" + }, + "source": [ + "## Monte Carlo\n", + "\n", + "*Exercise 7:* Write a \"generator\" function called `generate_function(func,x_min,x_max,N)`, that instead of generating a flat distribution, generates a distribution with functional form coded in `func`. Note that `func` will always be > 0. \n", + "\n", + "Use the test function below and your histogramming functions above to demonstrate that your generator is working properly.\n", + "\n", + "Hint: A simple, but slow, solution is to a draw random number test_x within the specified range and another number p between the min and max of the function (which you will have to determine). If p<=function(test_x), then place test_x on the output. If not, repeat the process, drawing two new numbers. Repeat until you have the specified number of generated numbers, N. For this problem, it's OK to determine the min and max by numerically sampling the function. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "NL7k4NeJ_1h1", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def generate_function(func,x_min,x_max,N=1000):\n", + " out = list()\n", + " ### BEGIN SOLUTION\n", + " d = (x_max - x_min) / N\n", + " numbers = [x * d + x_min for x in range(N + 1)]\n", + " frequency = [func(n * d + x_min) for n in range(N + 1)]\n", + " #aux = [frequency[0]] + [0] * N\n", + " for i in range(1, N + 1):\n", + " frequency[i] = (frequency[i - 1] + frequency[i])\n", + " #print(*zip(numbers, frequency))\n", + " #print(numbers)\n", + " #print(frequency)\n", + " while len(out) < N:\n", + " num = random.random() * frequency[-1]\n", + " #print(num)\n", + " for i in range(len(frequency)):\n", + " if frequency[i] >= num:\n", + " out.append(numbers[i])\n", + " #print(frequency[i], num)\n", + " break\n", + " ### END SOLUTION\n", + " \n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IOfuFLBX_1h6", + "colab_type": "code", + "outputId": "a5dc3747-a7ed-4987-c196-1ec4cb29e877", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "# A test function\n", + "def test_func(x,a=1,b=1):\n", + " return abs(a*x+b)\n", + "x_min = 0\n", + "x_max = 10\n", + "N = 1000\n", + "n_bins = 20\n", + "draw_histogram(generate_function(lambda x: -((x - 5)**2) + 5 ** 2, x_min, x_max, N), n_bins, x_min, x_max, \"#\", 50)\n", + "draw_histogram(generate_function(test_func, x_min, x_max, N), n_bins, x_min, x_max, \"#\", 50)" + ], + "execution_count": 19, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[ 0.000, 0.500] : ######\n", + "[ 0.500, 1.000] : ######\n", + "[ 1.000, 1.500] : ###################\n", + "[ 1.500, 2.000] : #########################\n", + "[ 2.000, 2.500] : #########################\n", + "[ 2.500, 3.000] : #########################################\n", + "[ 3.000, 3.500] : #####################################\n", + "[ 3.500, 4.000] : ###########################################\n", + "[ 4.000, 4.500] : #########################################\n", + "[ 4.500, 5.000] : #############################################\n", + "[ 5.000, 5.500] : ###########################################\n", + "[ 5.500, 6.000] : ##################################################\n", + "[ 6.000, 6.500] : ################################################\n", + "[ 6.500, 7.000] : ########################################\n", + "[ 7.000, 7.500] : ####################################\n", + "[ 7.500, 8.000] : ##############################\n", + "[ 8.000, 8.500] : #########################\n", + "[ 8.500, 9.000] : ###################\n", + "[ 9.000, 9.500] : #######\n", + "[ 9.500, 10.000] : #####\n", + "[ 0.000, 0.500] : #####\n", + "[ 0.500, 1.000] : ########\n", + "[ 1.000, 1.500] : ##############\n", + "[ 1.500, 2.000] : ############\n", + "[ 2.000, 2.500] : ##############\n", + "[ 2.500, 3.000] : ###################\n", + "[ 3.000, 3.500] : ####################\n", + "[ 3.500, 4.000] : #########################\n", + "[ 4.000, 4.500] : ##################\n", + "[ 4.500, 5.000] : ################################\n", + "[ 5.000, 5.500] : #############################\n", + "[ 5.500, 6.000] : ###########################\n", + "[ 6.000, 6.500] : ###################################\n", + "[ 6.500, 7.000] : ##################################\n", + "[ 7.000, 7.500] : #############################################\n", + "[ 7.500, 8.000] : #######################################\n", + "[ 8.000, 8.500] : #################################################\n", + "[ 8.500, 9.000] : ############################################\n", + "[ 9.000, 9.500] : ###############################################\n", + "[ 9.500, 10.000] : ##################################################\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "([10,\n", + " 14,\n", + " 26,\n", + " 22,\n", + " 25,\n", + " 34,\n", + " 35,\n", + " 44,\n", + " 33,\n", + " 57,\n", + " 52,\n", + " 47,\n", + " 61,\n", + " 60,\n", + " 79,\n", + " 69,\n", + " 86,\n", + " 77,\n", + " 82,\n", + " 87],\n", + " [0,\n", + " 0.5,\n", + " 1.0,\n", + " 1.5,\n", + " 2.0,\n", + " 2.5,\n", + " 3.0,\n", + " 3.5,\n", + " 4.0,\n", + " 4.5,\n", + " 5.0,\n", + " 5.5,\n", + " 6.0,\n", + " 6.5,\n", + " 7.0,\n", + " 7.5,\n", + " 8.0,\n", + " 8.5,\n", + " 9.0,\n", + " 9.5,\n", + " 10.0])" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 19 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "tEdnKUPz_1h-", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Use your function to generate 1000 numbers that are normal distributed, using the `gaussian` function below. Confirm the mean and variance of the data is close to the mean and variance you specify when building the Gaussian. Histogram the data. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "wnZFkATK_1h_", + "colab_type": "code", + "outputId": "ca30831f-6686-410f-b844-8d58e42c02ff", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 819 + } + }, + "source": [ + "import math\n", + "\n", + "def gaussian(mean, sigma):\n", + " def f(x):\n", + " return math.exp(-((x-mean)**2)/(2*sigma**2))/math.sqrt(math.pi*sigma)\n", + " return f\n", + "\n", + "# Example Instantiation\n", + "g1=gaussian(0,1)\n", + "g2=gaussian(10,3)\n", + "\n", + "g1_data = generate_function(g1, -4, 4, 1000)\n", + "g2_data = generate_function(g2, 0, 20, 1000)\n", + "print(g1_data)\n", + "print(g2_data)\n", + "draw_histogram(g1_data, 20)\n", + "print(\"g1 mean = \" + str(mean(g1_data)))\n", + "print(\"g1 variance = \" + str(variance(g1_data)))\n", + "draw_histogram(g2_data, 20)\n", + "print(\"g2 mean = \" + str(mean(g2_data)))\n", + "print(\"g2 variance = \" + str(variance(g2_data)))" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0.15200000000000014, 0.7519999999999998, 0.3360000000000003, -1.08, -1.104, -0.05600000000000005, -0.08000000000000007, -0.7839999999999998, -0.992, -0.32799999999999985, 0.3120000000000003, -0.21599999999999975, -0.8959999999999999, -0.552, 0.2240000000000002, 0.16800000000000015, 0.3600000000000003, -1.096, 0.04800000000000004, 1.12, 0.6479999999999997, -1.112, -0.3759999999999999, 0.5520000000000005, -0.45599999999999996, 0.984, 0.16000000000000014, -0.6640000000000001, 1.3680000000000003, -0.9039999999999999, -1.3599999999999999, 0.08000000000000007, -0.496, 0.8959999999999999, 1.096, -1.2719999999999998, 0.15200000000000014, -0.7439999999999998, -0.14400000000000013, 0.5120000000000005, 0.4400000000000004, 0.1200000000000001, -0.44799999999999995, 0.944, 0.3360000000000003, 0.968, -0.3039999999999998, -1.1840000000000002, -1.6959999999999997, -0.552, 0.07200000000000006, 0.6559999999999997, -1.024, 0.4240000000000004, -0.7599999999999998, -0.8959999999999999, -1.52, -0.6719999999999997, -0.9039999999999999, -1.496, 1.5120000000000005, 0.40800000000000036, -0.48, -0.04800000000000004, -0.8239999999999998, -0.7039999999999997, -0.8799999999999999, 1.3360000000000003, 0.09600000000000009, -0.9359999999999999, -1.1840000000000002, 0.08800000000000008, -1.3199999999999998, 0.7999999999999998, 0.2240000000000002, 0.16800000000000015, -0.3599999999999999, -0.8959999999999999, 0.17600000000000016, -0.33599999999999985, -0.528, -1.992, 1.2160000000000002, 1.2160000000000002, 1.3600000000000003, 1.7519999999999998, -0.472, -1.6720000000000002, -0.944, -0.528, 0.6879999999999997, 0.0, -0.3679999999999999, -0.7039999999999997, -1.6320000000000001, 1.1360000000000001, 0.7039999999999997, 2.4960000000000004, 1.2640000000000002, -0.8559999999999999, 0.2400000000000002, -0.8639999999999999, 0.3200000000000003, 0.8399999999999999, 0.20800000000000018, -0.2879999999999998, 1.3200000000000003, 1.6000000000000005, 0.5360000000000005, -0.976, -2.152, -1.064, -0.13600000000000012, 0.992, -0.536, -0.10400000000000009, -0.1120000000000001, -0.56, -0.7839999999999998, 0.7999999999999998, -0.2719999999999998, -1.2319999999999998, -0.13600000000000012, 2.032, -1.2559999999999998, -1.1999999999999997, -0.6959999999999997, 0.8399999999999999, 0.1280000000000001, 1.8559999999999999, 0.944, 0.7119999999999997, -1.376, -0.4159999999999999, -0.4079999999999999, 0.6239999999999997, 1.7359999999999998, 0.3440000000000003, -1.6480000000000001, 0.040000000000000036, 0.4400000000000004, 0.6959999999999997, -0.7599999999999998, 0.5520000000000005, -0.496, -0.6959999999999997, 0.3200000000000003, 0.952, 0.15200000000000014, 0.08800000000000008, 0.976, 0.19200000000000017, 0.38400000000000034, 0.7919999999999998, 0.9039999999999999, 1.6799999999999997, 0.3360000000000003, 1.3520000000000003, 0.03200000000000003, -1.464, -0.23999999999999977, -0.15200000000000014, 0.26400000000000023, -0.6959999999999997, 0.0, 0.4640000000000004, -0.944, 0.4560000000000004, 0.4640000000000004, 0.8879999999999999, -2.3120000000000003, -0.8319999999999999, 0.5200000000000005, -0.06400000000000006, 1.3840000000000003, -1.072, 2.056, -0.8639999999999999, -0.3839999999999999, 0.6799999999999997, -1.12, -0.7279999999999998, -0.22399999999999975, -2.048, 0.2320000000000002, -0.8159999999999998, 0.6319999999999997, -0.19999999999999973, 1.1840000000000002, -1.2639999999999998, 0.02400000000000002, -1.4, 0.03200000000000003, -1.576, -0.3599999999999999, 0.9119999999999999, -1.7119999999999997, -0.6799999999999997, -0.5760000000000001, -1.7519999999999998, -0.008000000000000007, -0.8079999999999998, -1.456, -0.5920000000000001, 0.9359999999999999, 0.8799999999999999, -0.08000000000000007, -0.09600000000000009, -1.2559999999999998, 1.6879999999999997, -1.112, -2.48, -0.7359999999999998, 0.5600000000000005, 0.30400000000000027, -0.5680000000000001, 0.6000000000000005, -0.6080000000000001, -1.6, 0.06400000000000006, 1.024, -1.1520000000000001, 2.024, 0.944, 1.8159999999999998, 0.06400000000000006, -0.8079999999999998, -0.008000000000000007, 0.4640000000000004, -0.008000000000000007, 0.3600000000000003, -0.6080000000000001, -0.976, 0.6639999999999997, -1.44, 1.8079999999999998, 0.20800000000000018, -0.6560000000000001, -0.6799999999999997, 0.8639999999999999, -0.8319999999999999, 0.16000000000000014, 0.6639999999999997, -0.008000000000000007, 0.4240000000000004, -0.952, 1.2000000000000002, 1.2640000000000002, -0.3919999999999999, -0.45599999999999996, -0.96, 2.0, 0.14400000000000013, 1.3520000000000003, -0.552, 0.5760000000000005, 0.0, 0.8719999999999999, -0.8079999999999998, -0.03200000000000003, -1.528, -0.05600000000000005, 0.008000000000000007, 0.4560000000000004, 1.04, 0.3520000000000003, -0.5680000000000001, -0.31999999999999984, 0.8079999999999998, -0.6240000000000001, 0.5120000000000005, -1.616, -0.46399999999999997, -0.1200000000000001, 0.7439999999999998, 0.19200000000000017, -0.8239999999999998, 0.008000000000000007, 1.976, 1.096, 0.8719999999999999, 1.024, 2.3200000000000003, 0.4800000000000004, 0.5200000000000005, -1.384, 0.3280000000000003, 0.8879999999999999, 0.6000000000000005, -0.03200000000000003, 0.8319999999999999, 0.7999999999999998, 0.5840000000000005, 1.064, -0.8959999999999999, -1.2159999999999997, -0.8639999999999999, -0.016000000000000014, 0.6399999999999997, 2.4640000000000004, -0.6320000000000001, -1.096, -1.2159999999999997, 0.24800000000000022, -0.7679999999999998, -0.2959999999999998, 0.15200000000000014, 2.152, -0.536, -0.8319999999999999, 0.4400000000000004, 0.16800000000000015, -2.7119999999999997, 1.032, -0.06400000000000006, -0.6160000000000001, -1.3279999999999998, -0.7599999999999998, 1.8159999999999998, -0.528, -0.6320000000000001, -0.7839999999999998, 0.5520000000000005, 0.016000000000000014, -0.6000000000000001, 0.992, 2.16, -0.22399999999999975, 1.2000000000000002, -0.6240000000000001, -0.13600000000000012, -1.6320000000000001, -0.7119999999999997, 1.056, 1.3360000000000003, -0.3919999999999999, 0.5840000000000005, 0.5680000000000005, -0.6000000000000001, 0.5200000000000005, -0.3679999999999999, 0.49600000000000044, -1.448, -0.23199999999999976, 1.3920000000000003, 0.2320000000000002, -0.46399999999999997, 0.3360000000000003, 0.26400000000000023, 0.5040000000000004, -0.984, 1.08, -0.976, -0.8079999999999998, -1.3119999999999998, 0.38400000000000034, -0.3919999999999999, 0.7279999999999998, 1.08, 0.8559999999999999, -0.19999999999999973, 1.032, 1.3280000000000003, -1.3439999999999999, 0.4640000000000004, -1.4, 1.5280000000000005, 0.2320000000000002, 0.7919999999999998, 0.08800000000000008, -1.016, -0.2559999999999998, 1.024, 0.15200000000000014, 0.3280000000000003, 0.7439999999999998, -0.8319999999999999, 0.7119999999999997, -0.7839999999999998, -0.22399999999999975, 1.984, 0.27200000000000024, -2.384, 0.6719999999999997, -0.7759999999999998, -0.1759999999999997, -1.7519999999999998, -1.1280000000000001, 0.96, 0.7679999999999998, 0.40800000000000036, 0.7199999999999998, 0.3600000000000003, -0.6320000000000001, -1.112, 0.3120000000000003, -0.1759999999999997, -1.032, -0.6640000000000001, 0.29600000000000026, -0.496, -0.7999999999999998, -1.448, 1.992, -0.7439999999999998, 0.5040000000000004, 1.4320000000000004, 0.38400000000000034, -0.4079999999999999, 1.6399999999999997, -0.8879999999999999, -1.8239999999999998, -0.7279999999999998, -0.7759999999999998, 1.3200000000000003, -1.048, -0.14400000000000013, 2.872, -0.9199999999999999, -2.528, 1.4480000000000004, -1.1999999999999997, -0.3759999999999999, 2.088, 0.13600000000000012, 0.6479999999999997, 0.008000000000000007, 1.2000000000000002, 0.08000000000000007, 0.28800000000000026, 0.8159999999999998, 0.24800000000000022, -0.04800000000000004, 1.4800000000000004, 0.8479999999999999, 1.08, -1.7519999999999998, -2.0, 0.03200000000000003, 0.30400000000000027, 0.02400000000000002, -2.248, 0.7039999999999997, 0.016000000000000014, 1.5520000000000005, 0.5360000000000005, 0.26400000000000023, 0.2240000000000002, 0.26400000000000023, -0.7039999999999997, -1.432, 0.6239999999999997, -0.6240000000000001, -1.968, -1.072, -0.15200000000000014, 0.2240000000000002, 0.16000000000000014, 1.064, -1.8479999999999999, 0.14400000000000013, 0.6959999999999997, 2.04, -0.02400000000000002, -0.1679999999999997, 0.6879999999999997, -0.040000000000000036, 0.7679999999999998, 2.856, -0.31999999999999984, -0.1280000000000001, 0.6959999999999997, 0.20000000000000018, -0.944, 0.8079999999999998, -1.2719999999999998, -1.984, -1.1360000000000001, -0.42399999999999993, 0.7999999999999998, -0.08800000000000008, -0.3839999999999999, 0.38400000000000034, -0.42399999999999993, 0.8799999999999999, 2.6080000000000005, -2.2720000000000002, 1.7999999999999998, 0.5680000000000005, -0.14400000000000013, 0.8719999999999999, 0.2560000000000002, 0.3280000000000003, 0.5840000000000005, 1.6799999999999997, -0.9359999999999999, -0.504, 0.5280000000000005, 0.08000000000000007, 1.7679999999999998, 0.5360000000000005, 0.5680000000000005, -0.1200000000000001, 0.20800000000000018, -1.416, -0.6719999999999997, -1.1760000000000002, -3.016, 2.6240000000000006, -0.6959999999999997, -0.56, -0.2719999999999998, 0.04800000000000004, -0.03200000000000003, -1.008, 2.088, 1.96, -1.1760000000000002, 0.28000000000000025, 0.040000000000000036, -0.3919999999999999, -0.1679999999999997, -0.6799999999999997, -0.8639999999999999, -1.56, 0.8799999999999999, 0.5040000000000004, 1.6959999999999997, -0.10400000000000009, -2.448, 0.07200000000000006, -0.9119999999999999, 0.016000000000000014, -1.408, -0.8559999999999999, -1.3439999999999999, 0.5440000000000005, 1.2640000000000002, -0.2799999999999998, -0.1679999999999997, -0.040000000000000036, 1.5920000000000005, -0.23199999999999976, 0.24800000000000022, 0.7279999999999998, 0.4320000000000004, 0.28000000000000025, -0.9279999999999999, 0.976, -1.1360000000000001, -0.8319999999999999, 0.6879999999999997, -0.04800000000000004, 0.48800000000000043, -0.33599999999999985, -0.22399999999999975, -1.888, -0.20799999999999974, -0.6160000000000001, 0.4320000000000004, 0.6080000000000005, -1.1360000000000001, -0.52, -0.008000000000000007, 1.2400000000000002, -0.7759999999999998, -0.1200000000000001, 0.17600000000000016, -0.18399999999999972, 2.4880000000000004, -0.7999999999999998, -1.6, -0.5760000000000001, -0.02400000000000002, -0.8399999999999999, 0.5120000000000005, 0.8079999999999998, 0.6399999999999997, -0.19999999999999973, 1.2560000000000002, 0.4320000000000004, -0.44799999999999995, 0.9359999999999999, 0.976, 2.7439999999999998, 0.3680000000000003, -1.432, -0.7199999999999998, 0.3200000000000003, 1.088, -0.1679999999999997, 0.28000000000000025, -0.3679999999999999, -0.040000000000000036, -0.34399999999999986, 1.6000000000000005, 0.6159999999999997, -1.2159999999999997, 0.09600000000000009, -2.2800000000000002, -1.0, -2.456, -1.2719999999999998, -1.08, -0.6000000000000001, -0.552, -0.23199999999999976, 0.5040000000000004, -0.8559999999999999, 0.03200000000000003, 0.040000000000000036, -0.1200000000000001, -0.06400000000000006, 0.02400000000000002, 1.6639999999999997, -2.56, -2.3040000000000003, -0.6959999999999997, 0.2400000000000002, 0.1280000000000001, 0.8639999999999999, 0.20000000000000018, -1.024, 0.1200000000000001, 2.4720000000000004, -0.2799999999999998, -0.15200000000000014, 0.04800000000000004, -1.6640000000000001, -1.3199999999999998, 0.16800000000000015, 0.06400000000000006, 1.0, 1.8479999999999999, -0.1759999999999997, -1.408, 0.5920000000000005, -1.072, 1.8719999999999999, -0.544, -0.18399999999999972, -1.8079999999999998, -1.392, 1.2160000000000002, 0.5920000000000005, -1.376, 1.072, -0.008000000000000007, 2.848, 2.096, -1.2719999999999998, -1.3199999999999998, -2.336, -1.1919999999999997, -0.7919999999999998, -0.544, 1.024, 0.03200000000000003, 0.5200000000000005, 0.3360000000000003, 0.2240000000000002, -0.536, 0.8399999999999999, 0.6639999999999997, -0.7519999999999998, -0.528, 1.2800000000000002, -0.05600000000000005, -0.1759999999999997, -0.7199999999999998, 1.3040000000000003, -0.33599999999999985, -1.096, 1.3280000000000003, 0.9119999999999999, -0.976, -0.5840000000000001, -1.1760000000000002, -0.544, -0.2879999999999998, -1.064, 0.09600000000000009, -0.7999999999999998, -0.3999999999999999, -1.2479999999999998, 1.2320000000000002, -0.1679999999999997, -0.488, 1.064, -0.9279999999999999, -0.31199999999999983, 0.3280000000000003, -0.8959999999999999, -0.34399999999999986, -0.5760000000000001, -0.8239999999999998, -0.7519999999999998, 0.8159999999999998, -0.4159999999999999, -0.10400000000000009, -0.6879999999999997, 0.7759999999999998, 0.27200000000000024, 0.5760000000000005, 1.8079999999999998, -2.096, 0.6239999999999997, 1.6319999999999997, 1.6240000000000006, -0.14400000000000013, 2.208, 0.16000000000000014, -1.016, 2.12, -1.456, -0.96, -0.008000000000000007, -1.6720000000000002, -1.0, 1.936, -1.2639999999999998, 0.06400000000000006, 0.5360000000000005, 0.8079999999999998, 1.064, -0.19999999999999973, 0.7999999999999998, -2.064, -1.056, 0.6479999999999997, -0.19199999999999973, 0.6159999999999997, -2.184, 0.29600000000000026, 0.49600000000000044, -0.6560000000000001, 0.8879999999999999, 0.8319999999999999, 0.6479999999999997, 1.1360000000000001, -1.7439999999999998, -1.592, 0.15200000000000014, 0.06400000000000006, 0.29600000000000026, -1.3439999999999999, -0.2799999999999998, -0.6959999999999997, -0.6320000000000001, -0.1679999999999997, -0.9039999999999999, -0.016000000000000014, -1.1760000000000002, -0.21599999999999975, -2.2640000000000002, -1.576, 2.128, -1.048, -0.5840000000000001, 0.1200000000000001, 0.38400000000000034, -0.6400000000000001, 1.1360000000000001, 1.1600000000000001, 1.072, 0.3440000000000003, 0.952, 1.08, 1.8399999999999999, 0.3120000000000003, -0.46399999999999997, -0.9039999999999999, -0.2719999999999998, -0.1759999999999997, -0.16000000000000014, 1.6000000000000005, 0.984, -2.088, 0.4800000000000004, -0.552, -1.7999999999999998, 0.28800000000000026, 1.3840000000000003, 0.5680000000000005, -1.6800000000000002, 1.5440000000000005, 0.7519999999999998, 0.1200000000000001, -0.488, 0.6080000000000005, 0.7199999999999998, 0.040000000000000036, -0.4159999999999999, -1.96, 0.16000000000000014, 1.5760000000000005, 0.14400000000000013, 0.6479999999999997, 0.0, 1.048, -0.496, 0.38400000000000034, 1.4640000000000004, -0.6480000000000001, 1.1760000000000002, 1.2320000000000002, 1.6559999999999997, -1.112, -2.392, -0.7599999999999998, -1.7919999999999998, -0.08000000000000007, -1.1999999999999997, 0.30400000000000027, -1.12, -0.5920000000000001, 0.49600000000000044, -0.7119999999999997, -0.2799999999999998, -0.22399999999999975, -0.9119999999999999, -0.3759999999999999, -1.3119999999999998, 0.17600000000000016, -0.08800000000000008, 0.1280000000000001, 1.7839999999999998, -0.2799999999999998, -0.2879999999999998, 0.7759999999999998, -0.7199999999999998, -1.7839999999999998, 0.6239999999999997, 0.05600000000000005, -0.21599999999999975, -1.04, -0.1120000000000001, -1.3519999999999999, -0.32799999999999985, 0.8559999999999999, -0.23199999999999976, -0.3839999999999999, 1.1920000000000002, -0.7199999999999998, 0.38400000000000034, -0.496, -0.23999999999999977, -0.7759999999999998, -0.1120000000000001, -0.23999999999999977, -1.392, 0.7999999999999998, -0.9359999999999999, -1.92, -0.07200000000000006, -1.7759999999999998, 0.2240000000000002, 1.4320000000000004, 1.08, -0.03200000000000003, -0.6160000000000001, 0.38400000000000034, 0.18400000000000016, -0.7359999999999998, -0.56, 0.8799999999999999, -0.3919999999999999, 1.1600000000000001, -1.456, -0.7999999999999998, -0.7119999999999997, -1.6, -1.6800000000000002, -1.2559999999999998, 1.1600000000000001, 0.5200000000000005, 2.176, -0.45599999999999996, -1.48, 1.0, -0.7919999999999998, -2.112, 0.7439999999999998, -1.3679999999999999, -0.496, -1.3359999999999999, 0.8879999999999999, -0.040000000000000036, -0.6400000000000001, 0.06400000000000006, -0.6879999999999997, -1.1999999999999997, -0.18399999999999972, 0.5200000000000005, 0.38400000000000034, -1.7839999999999998, -0.8319999999999999, 1.04, -1.7359999999999998, 0.5520000000000005, 1.2400000000000002, 0.4240000000000004, -0.040000000000000036, -0.8719999999999999, -0.7119999999999997, 0.20800000000000018, 1.4720000000000004, 0.4640000000000004, 0.5200000000000005, 0.5760000000000005, 0.4640000000000004, -1.1919999999999997, -0.9039999999999999, -1.2399999999999998, -1.584, 0.5280000000000005, 0.3120000000000003, 0.2320000000000002, -0.3839999999999999, 0.2400000000000002, 0.3200000000000003, -1.1680000000000001, 1.072, -1.7359999999999998, -0.31199999999999983, -0.15200000000000014, -1.4, -0.7839999999999998, -1.2079999999999997, 0.08800000000000008, 0.9199999999999999, 1.072, -0.1280000000000001, -0.992, -0.33599999999999985, -0.4159999999999999, 0.4720000000000004, 0.07200000000000006, 1.008, -1.096, -1.568, 1.0, 1.6559999999999997, -1.032, 2.6639999999999997, -1.1680000000000001, -1.096, 1.5200000000000005, 0.4240000000000004, -1.7279999999999998, -1.944, -0.10400000000000009, 0.984, -0.544, -1.3519999999999999, -0.5760000000000001, 0.8319999999999999, 0.4720000000000004, 0.24800000000000022, -1.072, -1.1999999999999997, -1.6959999999999997, -0.2719999999999998, -0.8079999999999998, 1.3200000000000003, 1.3040000000000003, 0.992, -0.3679999999999999, 1.6319999999999997, 0.1200000000000001, 0.016000000000000014, -0.512, 0.08000000000000007, -1.432, -0.10400000000000009, 0.040000000000000036, -0.7679999999999998, 1.984, 1.4080000000000004, 0.07200000000000006, 0.09600000000000009, 0.7759999999999998, 0.6399999999999997, 1.1840000000000002, 1.032, -0.7359999999999998, 0.7759999999999998, 0.4720000000000004, 0.28800000000000026, -0.536, 1.912, 0.9039999999999999, 1.4320000000000004, 1.5280000000000005, 0.16000000000000014, 0.9039999999999999, 0.3440000000000003, -2.376, -0.8479999999999999, 0.03200000000000003]\n", + "[9.74, 13.88, 8.42, 3.56, 8.4, 6.88, 8.78, 10.8, 11.78, 8.5, 12.26, 11.08, 10.0, 10.38, 11.72, 13.9, 8.9, 6.54, 8.52, 7.26, 3.5, 10.98, 11.64, 8.38, 10.14, 12.98, 8.84, 4.0200000000000005, 16.92, 11.94, 8.74, 9.34, 18.16, 8.64, 11.18, 12.58, 6.84, 11.120000000000001, 11.0, 9.56, 10.46, 10.72, 9.040000000000001, 5.64, 12.700000000000001, 11.46, 13.200000000000001, 11.44, 8.46, 10.76, 9.78, 9.72, 19.04, 9.56, 9.84, 11.3, 9.56, 11.14, 11.4, 7.2, 15.34, 8.540000000000001, 7.68, 7.16, 11.16, 10.1, 6.3, 9.94, 11.32, 4.22, 8.64, 5.08, 9.5, 10.620000000000001, 8.56, 11.6, 9.78, 12.68, 14.6, 9.540000000000001, 11.48, 11.14, 10.08, 9.84, 8.94, 6.3, 9.9, 13.96, 12.96, 8.4, 10.76, 7.34, 7.24, 11.700000000000001, 12.56, 13.74, 8.68, 12.58, 8.76, 12.72, 17.54, 5.66, 10.74, 8.72, 15.68, 7.62, 13.52, 11.36, 12.48, 12.58, 10.68, 5.62, 2.62, 9.64, 19.14, 13.14, 10.98, 10.56, 13.94, 11.58, 10.66, 4.92, 8.66, 8.6, 12.1, 10.32, 5.5200000000000005, 15.620000000000001, 8.32, 10.64, 8.84, 7.76, 7.96, 12.56, 13.14, 10.44, 9.700000000000001, 6.04, 8.22, 3.52, 5.36, 11.42, 9.66, 7.16, 12.6, 10.72, 12.040000000000001, 8.120000000000001, 10.18, 9.94, 8.4, 7.34, 10.44, 6.16, 10.02, 13.52, 15.06, 9.5, 12.64, 10.98, 8.94, 6.88, 11.36, 9.200000000000001, 8.3, 10.84, 11.040000000000001, 5.94, 10.48, 10.42, 6.08, 12.200000000000001, 10.72, 6.98, 12.88, 12.96, 5.08, 4.12, 10.86, 1.9000000000000001, 8.18, 10.1, 7.66, 10.18, 13.02, 9.36, 14.700000000000001, 9.200000000000001, 7.38, 10.06, 16.36, 14.96, 11.68, 8.68, 13.34, 10.5, 11.3, 12.22, 10.84, 9.14, 8.72, 8.52, 6.94, 9.78, 4.7, 2.9, 4.78, 12.84, 8.38, 15.700000000000001, 10.1, 8.96, 13.1, 8.66, 14.26, 16.12, 7.84, 12.200000000000001, 5.86, 14.16, 9.08, 12.6, 7.0200000000000005, 9.64, 9.84, 11.540000000000001, 11.82, 10.620000000000001, 15.860000000000001, 6.1000000000000005, 11.28, 14.120000000000001, 5.6000000000000005, 9.64, 6.68, 13.76, 10.84, 4.68, 11.32, 17.56, 8.44, 9.94, 7.140000000000001, 9.18, 9.94, 10.700000000000001, 8.6, 10.72, 11.9, 12.34, 9.4, 8.88, 9.5, 12.1, 8.32, 14.24, 14.64, 10.3, 7.92, 8.9, 9.42, 3.5, 5.96, 4.18, 11.200000000000001, 13.24, 13.34, 11.56, 10.42, 6.0, 12.040000000000001, 10.68, 6.62, 11.02, 12.32, 16.44, 8.4, 13.48, 13.66, 7.08, 7.08, 9.8, 10.620000000000001, 12.74, 8.18, 6.16, 10.72, 8.94, 5.96, 9.22, 8.28, 9.94, 13.42, 9.0, 10.86, 5.88, 5.4, 7.38, 11.8, 11.52, 12.540000000000001, 8.040000000000001, 7.82, 8.22, 7.4, 9.9, 14.4, 10.120000000000001, 4.68, 9.5, 9.44, 11.98, 12.06, 7.12, 13.8, 5.26, 13.02, 11.94, 6.5, 7.5, 15.46, 11.3, 9.98, 9.38, 7.08, 12.96, 15.0, 7.84, 10.94, 12.82, 8.44, 11.02, 11.620000000000001, 7.94, 7.12, 8.24, 4.0600000000000005, 7.18, 11.08, 15.34, 11.58, 10.98, 10.74, 4.36, 7.58, 13.82, 9.66, 6.8, 13.280000000000001, 10.32, 11.200000000000001, 16.56, 12.48, 7.26, 10.52, 10.94, 7.12, 10.58, 5.4, 7.54, 11.620000000000001, 12.42, 12.84, 10.84, 9.540000000000001, 11.02, 8.9, 11.44, 7.22, 10.76, 13.22, 14.36, 11.14, 8.72, 9.4, 6.54, 12.34, 7.08, 9.32, 7.140000000000001, 8.26, 13.0, 8.82, 12.98, 6.5200000000000005, 8.64, 6.28, 13.38, 8.44, 9.92, 8.8, 10.8, 12.9, 12.94, 13.4, 13.120000000000001, 7.74, 11.88, 9.1, 11.46, 8.18, 8.44, 6.48, 13.0, 7.94, 9.38, 8.700000000000001, 14.92, 11.3, 13.34, 1.4000000000000001, 7.54, 9.52, 8.22, 15.82, 9.48, 8.64, 7.9, 7.3, 11.36, 13.14, 5.78, 10.36, 6.5600000000000005, 5.96, 12.700000000000001, 11.620000000000001, 15.68, 9.88, 14.24, 8.88, 8.76, 11.52, 9.72, 12.32, 12.1, 4.12, 7.7, 9.92, 14.44, 2.44, 13.36, 11.44, 14.46, 16.82, 10.38, 9.14, 5.66, 15.0, 10.44, 9.74, 7.34, 12.48, 9.14, 7.22, 4.34, 11.02, 10.92, 9.28, 9.44, 7.7, 9.24, 10.18, 9.78, 12.540000000000001, 11.08, 9.28, 11.58, 8.18, 11.36, 12.96, 7.22, 6.4, 6.9, 10.4, 11.28, 12.48, 5.0200000000000005, 15.4, 11.0, 10.28, 12.6, 6.5200000000000005, 14.46, 3.2800000000000002, 10.74, 10.48, 13.5, 9.120000000000001, 8.620000000000001, 3.38, 7.24, 6.32, 12.76, 11.48, 10.58, 7.38, 10.56, 8.34, 8.66, 12.44, 6.0, 13.92, 12.9, 11.72, 10.620000000000001, 7.18, 12.98, 14.6, 8.38, 10.040000000000001, 12.48, 12.32, 9.06, 12.0, 9.700000000000001, 9.040000000000001, 12.22, 11.700000000000001, 0.86, 11.22, 5.0, 6.94, 11.32, 13.44, 13.6, 5.46, 11.66, 10.0, 8.58, 3.02, 9.26, 8.96, 10.88, 8.02, 11.9, 16.96, 8.38, 11.9, 12.040000000000001, 13.96, 13.94, 9.34, 5.36, 13.86, 9.14, 7.5600000000000005, 7.88, 10.64, 10.4, 14.280000000000001, 10.14, 8.52, 7.9, 8.78, 11.540000000000001, 10.18, 8.040000000000001, 10.56, 9.92, 8.08, 10.26, 7.54, 6.34, 5.14, 9.3, 10.64, 9.200000000000001, 7.140000000000001, 7.44, 7.54, 13.42, 4.34, 6.4, 9.38, 10.96, 10.82, 11.66, 9.0, 8.02, 10.14, 10.82, 10.4, 12.44, 8.620000000000001, 9.98, 6.58, 12.02, 9.14, 12.18, 7.28, 7.24, 11.120000000000001, 12.88, 8.38, 11.48, 12.64, 10.120000000000001, 13.14, 9.06, 11.700000000000001, 9.02, 7.42, 8.620000000000001, 8.26, 9.78, 8.48, 14.02, 5.34, 11.46, 5.94, 6.62, 12.9, 8.3, 15.58, 6.0600000000000005, 7.62, 14.8, 6.36, 10.120000000000001, 6.38, 9.72, 10.68, 7.48, 9.72, 6.54, 10.72, 14.16, 9.120000000000001, 9.86, 8.44, 9.82, 12.66, 5.7, 8.48, 14.58, 10.02, 6.640000000000001, 12.06, 6.22, 8.28, 13.46, 11.42, 9.88, 4.6000000000000005, 9.32, 13.200000000000001, 5.7, 9.48, 5.42, 6.1000000000000005, 5.6000000000000005, 11.9, 11.24, 10.700000000000001, 16.2, 12.92, 9.86, 13.26, 9.5, 9.38, 5.4, 9.0, 8.68, 9.94, 3.8000000000000003, 9.3, 10.8, 9.6, 17.1, 10.96, 13.48, 12.88, 15.42, 11.72, 14.780000000000001, 13.620000000000001, 10.78, 9.52, 5.3, 14.200000000000001, 8.64, 11.14, 6.9, 2.42, 9.28, 13.74, 9.96, 11.18, 17.52, 8.42, 12.02, 12.620000000000001, 12.58, 11.24, 10.32, 8.36, 13.98, 12.38, 13.86, 8.86, 11.44, 10.3, 10.92, 5.5600000000000005, 15.280000000000001, 10.32, 9.02, 5.1000000000000005, 10.6, 10.78, 7.3, 7.44, 8.22, 9.26, 7.12, 2.46, 12.700000000000001, 6.3, 12.44, 7.3, 7.28, 16.3, 9.76, 3.92, 10.44, 7.34, 9.46, 6.76, 7.640000000000001, 2.2600000000000002, 7.08, 10.52, 14.3, 3.0, 8.36, 8.620000000000001, 9.88, 14.040000000000001, 10.0, 14.44, 5.54, 12.48, 8.8, 12.16, 11.68, 10.42, 10.8, 7.32, 13.42, 11.26, 6.82, 5.08, 6.6000000000000005, 7.92, 11.120000000000001, 14.1, 9.82, 7.24, 6.58, 15.18, 7.5600000000000005, 9.82, 4.36, 10.58, 14.32, 6.9, 9.58, 10.34, 5.58, 11.540000000000001, 11.26, 5.5600000000000005, 9.6, 9.06, 8.74, 4.5200000000000005, 9.92, 10.72, 10.52, 5.72, 6.86, 10.78, 14.84, 15.82, 4.72, 10.120000000000001, 10.74, 10.68, 15.36, 12.92, 9.74, 10.52, 6.9, 4.3, 10.52, 4.04, 5.22, 11.540000000000001, 8.9, 12.8, 1.3, 10.66, 8.64, 9.8, 11.94, 9.200000000000001, 11.88, 7.7, 6.72, 9.8, 10.46, 15.56, 10.88, 7.0200000000000005, 9.200000000000001, 11.540000000000001, 8.06, 6.5, 13.56, 9.08, 10.6, 10.120000000000001, 9.32, 5.5600000000000005, 8.28, 10.9, 9.96, 9.16, 11.44, 13.72, 12.32, 12.72, 4.6000000000000005, 13.0, 11.46, 14.92, 5.98, 11.18, 11.48, 5.12, 15.58, 9.44, 12.3, 8.84, 12.68, 10.58, 16.34, 10.94, 10.46, 7.5600000000000005, 11.18, 12.5, 8.02, 7.94, 12.56, 8.2, 6.76, 11.58, 13.48, 9.52, 8.2, 9.34, 6.38, 13.280000000000001, 10.14, 9.16, 11.26, 8.9, 9.88, 9.6, 9.82, 6.86, 7.86, 13.0, 13.92, 9.22, 7.38, 9.98, 11.16, 10.46, 11.96, 6.98, 11.08, 12.34, 10.1, 12.52, 4.12, 8.86, 9.200000000000001, 8.08, 12.66, 15.88, 10.02, 6.24, 8.92, 12.98, 14.76, 9.74, 8.36, 14.84, 9.98, 10.74, 11.78, 12.64, 10.82, 13.3, 3.7600000000000002, 16.02, 4.38, 13.120000000000001, 11.06, 10.8, 9.88, 6.16, 11.58, 12.0, 10.24, 7.48, 11.22, 12.72, 5.62, 6.98, 7.2, 5.98, 8.5, 12.4, 9.02, 8.82, 13.02, 11.200000000000001, 8.5, 9.78, 7.7, 6.7, 12.22, 7.1000000000000005, 13.36, 5.04, 10.78, 8.76, 10.42, 7.6000000000000005, 3.48, 9.78, 8.0, 10.78, 10.56, 5.04, 8.64, 13.76, 12.84, 12.94, 7.6000000000000005, 13.48, 15.0, 4.0, 14.280000000000001, 9.28, 7.16, 7.08, 4.5200000000000005, 10.14, 11.72, 7.16, 6.26, 6.44, 10.44, 10.8, 11.76, 12.38, 9.92, 12.5, 12.120000000000001, 12.46, 6.32, 7.54, 14.18, 7.5200000000000005, 14.620000000000001, 9.8, 9.16, 6.9, 13.040000000000001, 14.74, 11.02, 6.32, 9.700000000000001, 15.280000000000001, 6.3, 13.8, 9.200000000000001, 6.18, 8.94, 12.72, 8.56, 8.5, 7.96, 7.48, 12.92]\n", + "[ -3.016, -2.722] : \n", + "[ -2.722, -2.427] : #\n", + "[ -2.427, -2.133] : ##\n", + "[ -2.133, -1.838] : ##\n", + "[ -1.838, -1.544] : #####\n", + "[ -1.544, -1.250] : ########\n", + "[ -1.250, -0.955] : ###########\n", + "[ -0.955, -0.661] : #################\n", + "[ -0.661, -0.366] : ################\n", + "[ -0.366, -0.072] : ################\n", + "[ -0.072, 0.222] : ####################\n", + "[ 0.222, 0.517] : #################\n", + "[ 0.517, 0.811] : ###############\n", + "[ 0.811, 1.106] : #############\n", + "[ 1.106, 1.400] : #######\n", + "[ 1.400, 1.694] : ####\n", + "[ 1.694, 1.989] : ###\n", + "[ 1.989, 2.283] : ##\n", + "[ 2.283, 2.578] : \n", + "[ 2.578, 2.872] : #\n", + "g1 mean = -0.0460959999999999\n", + "g1 variance = 1.0227577187840005\n", + "[ 0.860, 1.774] : \n", + "[ 1.774, 2.688] : \n", + "[ 2.688, 3.602] : #\n", + "[ 3.602, 4.516] : ##\n", + "[ 4.516, 5.430] : ####\n", + "[ 5.430, 6.344] : #######\n", + "[ 6.344, 7.258] : ###########\n", + "[ 7.258, 8.172] : ##########\n", + "[ 8.172, 9.086] : ##################\n", + "[ 9.086, 10.000] : ####################\n", + "[ 10.000, 10.914] : ##################\n", + "[ 10.914, 11.828] : ################\n", + "[ 11.828, 12.742] : ############\n", + "[ 12.742, 13.656] : ##########\n", + "[ 13.656, 14.570] : ######\n", + "[ 14.570, 15.484] : ####\n", + "[ 15.484, 16.398] : ##\n", + "[ 16.398, 17.312] : \n", + "[ 17.312, 18.226] : \n", + "[ 18.226, 19.140] : \n", + "g2 mean = 9.911780000000002\n", + "g2 variance = 8.671936831599995\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "0X96qgN8_1iD", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Combine your `generate_function`, `where`, and `in_range` functions above to create an integrate function. Use your integrate function to show that approximately 68% of Normal distribution is within one variance." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "A51dSStW_1iF", + "colab_type": "code", + "outputId": "7d1b1f31-1786-4d1c-ae00-0249023581e9", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + } + }, + "source": [ + "def integrate(func, x_min, x_max, n_points=1000):\n", + " # monte carlo integral\n", + " # max f(x) over [x_min, x_max] in steps of (1/1000 or 1/n_points) * the difference\n", + " f_max = max([func(x) for x in [x_min + n * (x_max - x_min) / max(1000, n_points) for n in range(max(1000, n_points))]])\n", + " # generate n_points random x and y values on a grid x = [x_min, x_max] and y = [0, f_max]\n", + " x_rand = [x_min + random.random() * (x_max - x_min) for n in range(n_points)]\n", + " y_rand = [random.random() * f_max for n in range(n_points)]\n", + " # return height * width * (# of points on grid below the function curve)\n", + " # # of pts where passing x and y as tuples 0 < y < func(x)\n", + " return f_max * (x_max - x_min) * len(where(list(zip(x_rand, y_rand)), lambda xy: in_range(0, func(xy[0]))(xy[1]))) / n_points\n", + "\n", + "\n", + "def integrate_properly(func, x_min, x_max, n_points=1000):\n", + " # proper integral\n", + " i = x_min\n", + " integral = 0\n", + " dx = (x_max - x_min) / n_points\n", + " while i < x_max:\n", + " integral += func(i) * dx\n", + " i += dx\n", + " return integral\n", + "\n", + "mc_integral = integrate(lambda x: -((x - 10) ** 2) + 100, 0, 20, 10000)\n", + "proper_integral = integrate_properly(lambda x: -((x - 10) ** 2) + 100, 0, 20, 10000)\n", + "print(\"Integral from {:d} to \".format(x_min) + \"{:d} of -((x - 10) ^ 2) + 100:\".format(x_max))\n", + "print(\" data: {:4.3f}\".format(mc_integral))\n", + "print(\" theory: {:4.3f}\".format(proper_integral))\n", + "print(\" % error: {:3.1f}%\".format(100*abs(mc_integral-proper_integral)/proper_integral))\n", + "data_norm_integral = integrate(g2, 7, 13, 10000)/integrate(g2, 0, 20, 10000)\n", + "proper_norm_integral = integrate_properly(g2, 7, 13, 10000)/integrate_properly(g2, 0, 20, 10000)\n", + "print(\"Percent of Normal distribution within one variance:\")\n", + "print(\" data: {:3.1f}%\".format(100*data_norm_integral))\n", + "print(\" theory: {:3.1f}%\".format(100*proper_norm_integral))\n", + "print(\" % error: {:3.1f}%\".format(100*abs(data_norm_integral-proper_norm_integral)/proper_norm_integral))" + ], + "execution_count": 36, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Integral from 0 to 10 of -((x - 10) ^ 2) + 100:\n", + " data: 1324.600\n", + " theory: 1333.333\n", + " % error: 0.7%\n", + "Percent of Normal distribution within one variance:\n", + " data: 68.2%\n", + " theory: 68.3%\n", + " % error: 0.1%\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "d87Vi_Zj_1iL", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-5/Lab-5 - Copy.ipynb b/Labs/Lab-5/Lab-5 - Copy.ipynb new file mode 100644 index 0000000..3b82dad --- /dev/null +++ b/Labs/Lab-5/Lab-5 - Copy.ipynb @@ -0,0 +1,551 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab 5- Object Oriented Programming\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-5/Lab-5.ipynb)\n", + "\n", + "For all of the exercises below, make sure you provide tests of your solutions.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Write a \"counter\" class that can be incremented up to a specified maximum value, will print an error if an attempt is made to increment beyond that value, and allows reseting the counter. " + ] + }, + { + "cell_type": "code", + "execution_count": 102, + "metadata": {}, + "outputs": [], + "source": [ + "class counter:\n", + " def __init__(self,max_val):\n", + " self.max_val=max_val\n", + " self.cur_val=1\n", + " \n", + " def increment(self):\n", + " if self.cur_val>self.max_val:\n", + " print(\"Max value reached.\")\n", + " else:\n", + " self.cur_val+=1\n", + " \n", + " def reset(self):\n", + " self.cur_val=1\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 103, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 104, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max value reached.\n", + "Max value reached.\n" + ] + } + ], + "source": [ + "my_counter.increment()\n", + "my_counter.increment()\n", + "my_counter.increment()\n", + "my_counter.increment()\n", + "my_counter.increment()" + ] + }, + { + "cell_type": "code", + "execution_count": 105, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter.cur_val=100" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Copy and paste your solution to question 1 and modify it so that all the data held by the counter is private. Implement functions to check the value of the counter, check the maximum value, and check if the counter is at the maximum." + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [], + "source": [ + "class counter:\n", + " def __init__(self,max_val):\n", + " self.__max_val=max_val\n", + " self.__cur_val=1\n", + " \n", + " def increment(self):\n", + " if self.__cur_val>self.__max_val:\n", + " print(\"Max value reached.\")\n", + " else:\n", + " self.__cur_val+=1\n", + " \n", + " def reset(self):\n", + " self.__cur_val=1\n", + " \n", + " def cur_val(self):\n", + " return self.__cur_val\n", + "\n", + " def max_val(self):\n", + " return self.__max_val\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 108, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_counter.cur_val()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Implement a class to represent a rectangle, holding the length, width, and $x$ and $y$ coordinates of a corner of the object. Implement functions that compute the area and parameter of the rectangle. Make all data members private and privide accessors to retrieve values of data members. " + ] + }, + { + "cell_type": "code", + "execution_count": 109, + "metadata": {}, + "outputs": [], + "source": [ + "class rectangle:\n", + " def __init__(self,width,length,x,y):\n", + " self.__width=width\n", + " self.__length=length\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " def area(self):\n", + " return self.__width*self.__length\n", + " \n", + " def perimeter(self):\n", + " return 2*(self.__width+self.__length)\n", + " \n", + " def x(self):\n", + " return self.__x\n", + " \n", + " def y(self):\n", + " return self.__y\n", + " \n", + " def width(self):\n", + " return self.__width\n", + " \n", + " def length(self):\n", + " return self.__length\n" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "6\n", + "10\n", + "1\n", + "4\n", + "2\n", + "3\n" + ] + } + ], + "source": [ + "my_rectangle = rectangle(2,3,1,4)\n", + "print(my_rectangle.area())\n", + "print(my_rectangle.perimeter())\n", + "print(my_rectangle.x())\n", + "print(my_rectangle.y())\n", + "print(my_rectangle.width())\n", + "print(my_rectangle.length())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Implement a class to represent a circle, holding the radius and $x$ and $y$ coordinates of center of the object. Implement functions that compute the area and parameter of the rectangle. Make all data members private and privide accessors to retrieve values of data members. " + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "\n", + "class circle:\n", + " def __init__(self, radius, x, y):\n", + " self.__radius = radius\n", + " self.__x = x\n", + " self.__y = y\n", + " \n", + " def area(self):\n", + " return math.pi * self.__radius**2\n", + " \n", + " def perimeter(self):\n", + " return 2 * math.pi * self.__radius\n", + " \n", + " def radius(self):\n", + " return self.__radius\n", + " \n", + " def x(self):\n", + " return self.__x\n", + " \n", + " def y(self):\n", + " return self.__y" + ] + }, + { + "cell_type": "code", + "execution_count": 112, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.566370614359172\n", + "12.566370614359172\n", + "2\n", + "0\n", + "0\n" + ] + } + ], + "source": [ + "my_circle = circle(2,0,0)\n", + "print(my_circle.area())\n", + "print(my_circle.perimeter())\n", + "print(my_circle.radius())\n", + "print(my_circle.x())\n", + "print(my_circle.y())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Implement a common base class for the classes implemented in 3 and 4 above which implements all common methods as dummy functions. Re-implement those classes to inherit from the base class and overload the functions accordingly. " + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [], + "source": [ + "class shape:\n", + " def __init__(self, x, y):\n", + " self.__x = x\n", + " self.__y = y\n", + " \n", + " def x(self):\n", + " return self.__x\n", + " \n", + " def y(self):\n", + " return self.__y\n", + " \n", + " def area(self):\n", + " raise NotImplementedError\n", + " \n", + " def perimeter(self):\n", + " raise NotImplementedError\n", + "\n", + "class rectangle(shape):\n", + " def __init__(self,width,length,x,y):\n", + " super().__init__(x, y)\n", + " self.__width=width\n", + " self.__length=length\n", + " \n", + " def area(self):\n", + " return self.__width*self.__length\n", + " \n", + " def perimeter(self):\n", + " return 2*(self.__width+self.__length)\n", + " \n", + " def x(self):\n", + " return super().x()\n", + " \n", + " def y(self):\n", + " return super().y()\n", + " \n", + " def width(self):\n", + " return self.__width\n", + " \n", + " def length(self):\n", + " return self.__length\n", + "\n", + "class circle(shape):\n", + " def __init__(self, radius, x, y):\n", + " super().__init__(x, y)\n", + " self.__radius = radius\n", + " \n", + " def area(self):\n", + " return math.pi * self.__radius**2\n", + " \n", + " def perimeter(self):\n", + " return 2 * math.pi * self.__radius\n", + " \n", + " def radius(self):\n", + " return self.__radius\n", + " \n", + " def x(self):\n", + " return super().x()\n", + " \n", + " def y(self):\n", + " return super().y()" + ] + }, + { + "cell_type": "code", + "execution_count": 149, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "5\n", + "6\n", + "10\n", + "12.566370614359172\n", + "12.566370614359172\n" + ] + } + ], + "source": [ + "my_shape = shape(5,5)\n", + "print(my_shape.x())\n", + "print(my_shape.y())\n", + "my_rectangle = rectangle(3, 2, -1.5,-0.5)\n", + "print(my_rectangle.area())\n", + "print(my_rectangle.perimeter())\n", + "my_circle = circle(2, 0, 0)\n", + "print(my_circle.area())\n", + "print(my_circle.perimeter())\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Implement an analogous triangle class." + ] + }, + { + "cell_type": "code", + "execution_count": 150, + "metadata": {}, + "outputs": [], + "source": [ + "class triangle(shape):\n", + " def __init__(self, x1, y1, x2, y2, x3, y3):\n", + " super().__init__(x1, y1)\n", + " self.__x2 = x2\n", + " self.__y2 = y2\n", + " self.__x3 = x3\n", + " self.__y3 = y3\n", + " \n", + " def x1(self):\n", + " return super().x()\n", + " def y1(self):\n", + " return super().y()\n", + " def x2(self):\n", + " return self.__x2\n", + " def y2(self):\n", + " return self.__y2\n", + " def x3(self):\n", + " return self.__x3\n", + " def y3(self):\n", + " return self.__y3\n", + " \n", + " def area(self):\n", + " return abs((self.x1()*(self.__y2-self.__y3) + self.__x2*(self.__y3-self.y1()) + self.__x3*(self.y1()-self.__y2))/2)\n", + " \n", + " def perimeter(self):\n", + " return math.sqrt((self.__x2-super().x())**2+(self.__y2-super().y())**2) + math.sqrt((self.__x3-self.__x2)**2+(self.__y3-self.__y2)**2) + math.sqrt((super().x()-self.__x3)**2+(super().x()-self.__y3)**2)" + ] + }, + { + "cell_type": "code", + "execution_count": 151, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "0\n", + "1.0\n", + "5.23606797749979\n" + ] + } + ], + "source": [ + "my_triangle = triangle(0,0,1,0,1,2)\n", + "print(my_triangle.x())\n", + "print(my_triangle.x1())\n", + "print(my_triangle.area())\n", + "print(my_triangle.perimeter())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "7. Add a function to the object classes that test if a given set of $x$ and $y$ coordinates are inside of the object." + ] + }, + { + "cell_type": "code", + "execution_count": 152, + "metadata": {}, + "outputs": [], + "source": [ + "setattr(triangle,'inside', lambda self, x, y: triangle(x, y, self.x2(), self.y2(), self.x3(), self.y3()).area() + triangle(self.x1(), self.y1(), x, y, self.x3(), self.y3()).area() + triangle(self.x1(), self.y1(), self.x2(), self.y2(), x, y).area() == self.area())\n", + "setattr(circle,'inside', lambda self, x, y: math.sqrt((self.x()-x)**2+(self.y()-y)**2) <= self.radius())\n", + "setattr(rectangle,'inside', lambda self, x, y: self.x()<=x<=self.x()+self.width() and self.y()<=y<=self.y()+self.length())" + ] + }, + { + "cell_type": "code", + "execution_count": 154, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "\n", + "True\n", + "True\n", + "True\n", + "False\n", + "\n", + "True\n", + "True\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "print(my_triangle.inside(0.75, 0.25))\n", + "print(my_triangle.inside(0.25, 0.75))\n", + "print(my_triangle.inside(0.5,0.5))\n", + "print()\n", + "print(my_circle.inside(0,0))\n", + "print(my_circle.inside(0,1))\n", + "print(my_circle.inside(0,2))\n", + "print(my_circle.inside(0,3))\n", + "print()\n", + "print(my_rectangle.inside(-1.5,0))\n", + "print(my_rectangle.inside(0,0))\n", + "print(my_rectangle.inside(1.5,0))\n", + "print(my_rectangle.inside(1.6,0))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "8. Add a function to the object classes that return a list of up to 16 pairs of $x$ and $y$ points on the parameter of the object.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "9. Add a function in the base class of the object classes that returns true/false testing that the object overlaps with another object." + ] + } + ], + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Labs/Lab-6/Lab-6 - Copy.ipynb b/Labs/Lab-6/Lab-6 - Copy.ipynb new file mode 100644 index 0000000..b172fda --- /dev/null +++ b/Labs/Lab-6/Lab-6 - Copy.ipynb @@ -0,0 +1,510 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab 6\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Matrix Representation: In this lab you will be creating a simple linear algebra system. In memory, we will represent matrices as nested python lists as we have done in lecture. \n", + "\n", + "1. Create a `matrix` class with the following properties:\n", + " * It can be initialized in 2 ways:\n", + " 1. with arguments `n` and `m`, the size of the matrix. A newly instanciated matrix will contain all zeros.\n", + " 2. with a list of lists of values. Note that since we are using lists of lists to implement matrices, it is possible that not all rows have the same number of columns. Test explicitly that the matrix is properly specified.\n", + " * Matrix instances `M` can be indexed with `M[i][j]` and `M[i,j]`.\n", + " * Matrix assignment works in 2 ways:\n", + " 1. If `M_1` and `M_2` are `matrix` instances `M_1=M_2` sets the values of `M_1` to those of `M_2`, if they are the same size. Error otherwise.\n", + " 2. In example above `M_2` can be a list of lists of correct size.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 248, + "metadata": {}, + "outputs": [], + "source": [ + "class matrix:\n", + " _M = None\n", + " def __init__(self, *args):\n", + " if isinstance(args[0], list):\n", + " if (isinstance(args[0][_], list) for _ in range(len(args[0]))):\n", + " lengths = set(len(args[0][_]) for _ in range(len(args[0])))\n", + " if len(lengths) == 1:\n", + " self._M = args[0]\n", + " elif isinstance(args[0], int) and isinstance(args[1], int):\n", + " self._M = [[0 for _ in range(args[1])] for __ in range(args[0])]\n", + " \n", + " def __getitem__(self, index):\n", + " if isinstance(index, tuple):\n", + " i, j = index\n", + " return self._M[i][j]\n", + " else:\n", + " return self._M[index]\n", + " \n", + " def __str__(self):\n", + " return str(self._M)" + ] + }, + { + "cell_type": "code", + "execution_count": 249, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "M=matrix(2,3): [[0, 0, 0], [0, 0, 0]]\n", + "M=matrix([[],[]]): [[1, 2, 3], [4, 5, 6]]\n", + "M[1][0]: 4\n", + "M[1,0]: 4\n", + "M = M2: [[2, 3], [4, 5], [6, 7]]\n" + ] + } + ], + "source": [ + "M = matrix(2,3)\n", + "print(\"M=matrix(2,3): {}\".format(M))\n", + "M = matrix([[1,2,3],[4,5,6]])\n", + "print(\"M=matrix([[],[]]): {}\".format(M))\n", + "print(\"M[1][0]: {}\".format(M[1][0]))\n", + "print(\"M[1,0]: {}\".format(M[1,0]))\n", + "# can't figure out how to override assignment operator\n", + "M2 = matrix([[2,3],[4,5],[6,7]])\n", + "M = M2\n", + "print(\"M = M2: {}\".format(M))\n", + "#M = [[3,4],[5,6],[7,8]]\n", + "#print(\"M=[[],[],[]]\".format(M.M()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Add the following methods:\n", + " * `shape()`: returns a tuple `(n,m)` of the shape of the matrix.\n", + " * `transpose()`: returns a new matrix instance which is the transpose of the matrix.\n", + " * `row(n)` and `column(n)`: that return the nth row or column of the matrix M as a new appropriately shaped matrix object.\n", + " * `to_list()`: which returns the matrix as a list of lists.\n", + " * `block(n_0,n_1,m_0,m_1)` that returns a smaller matrix located at the n_0 to n_1 columns and m_0 to m_1 rows. \n", + " * (Extra credit) Modify `__getitem__` implemented above to support slicing.\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 250, + "metadata": {}, + "outputs": [], + "source": [ + "def shape(self):\n", + " return len(self._M), len(self._M[0])\n", + "\n", + "def transpose(self):\n", + " n, m = self.shape()\n", + " M = matrix(m,n)\n", + " for _ in range(m):\n", + " for __ in range(n):\n", + " M[_][__] = self._M[__][_]\n", + " return M\n", + "\n", + "def row(self, n):\n", + " return matrix([self._M[n]])\n", + "def column(self, n):\n", + " return matrix([self.transpose()._M[n]])\n", + "\n", + "def to_list(self):\n", + " return self._M\n", + "\n", + "def block(self, n_0, n_1, m_0, m_1):\n", + " if 0 <= n_0 and 0 <= m_0 and n_1 <= len(self._M) and m_1 <= len(self.transpose()._M):\n", + " ml = [[0 for _ in range(m_1-m_0)] for __ in range(n_1-n_0)]\n", + " for n in range(n_0, n_1):\n", + " for m in range(m_0, m_1):\n", + " ml[n-n_0][m-m_0] = self._M[n][m]\n", + " return matrix(ml)\n", + " else:\n", + " return None\n", + "\n", + "# modification was not necessary but now explicit\n", + "def __getitem__(self, index):\n", + " if isinstance(index, tuple):\n", + " i, j = index\n", + " return self._M[i][j]\n", + " elif isinstance(index, slice):\n", + " return self._M[index]\n", + " else:\n", + " return self._M[index]\n", + "\n", + "setattr(matrix, 'shape', shape)\n", + "setattr(matrix, 'transpose', transpose)\n", + "setattr(matrix, 'row', row)\n", + "setattr(matrix, 'column', column)\n", + "setattr(matrix, 'to_list', to_list)\n", + "setattr(matrix, 'block', block)\n", + "setattr(matrix, '__getitem__', __getitem__)" + ] + }, + { + "cell_type": "code", + "execution_count": 265, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "M: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", + "M.shape(): (3, 3)\n", + "M.transpose()._M: [[1, 4, 7], [2, 5, 8], [3, 6, 9]]\n", + "M.row(0)._M: [[1, 2, 3]]\n", + "M.column(0)._M: [[1, 4, 7]]\n", + "M.to_list(): [[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n", + "M.block(0,2,0,2): [[1, 2], [4, 5]]\n", + "M[:][:2]: [[1, 2, 3], [4, 5, 6]]\n" + ] + } + ], + "source": [ + "M = matrix([[1,2,3],[4,5,6],[7,8,9]])\n", + "print(\"M: {}\".format(M))\n", + "print(\"M.shape(): {}\".format(M.shape()))\n", + "print(\"M.transpose()._M: {}\".format(M.transpose()))\n", + "print(\"M.row(0)._M: {}\".format(M.row(0)))\n", + "print(\"M.column(0)._M: {}\".format(M.column(0)))\n", + "print(\"M.to_list(): {}\".format(M.to_list()))\n", + "print(\"M.block(0,2,0,2): {}\".format(M.block(0,2,0,2).to_list()))\n", + "print(\"M[:][:2]: {}\".format(M[:2]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Write functions that create special matrices (note these are standalone functions, not member functions of your `matrix` class):\n", + " * `constant(n,m,c)`: returns a `n` by `m` matrix filled with floats of value `c`.\n", + " * `zeros(n,m)` and `ones(n,m)`: return `n` by `m` matrices filled with floats of value `0` and `1`, respectively.\n", + " * `eye(n)`: returns the n by n identity matrix." + ] + }, + { + "cell_type": "code", + "execution_count": 252, + "metadata": {}, + "outputs": [], + "source": [ + "def constant(n,m,c):\n", + " return matrix([[c for _ in range(m)] for __ in range(n)])\n", + "\n", + "def zeros(n,m):\n", + " return matrix([[0.0 for _ in range(m)] for __ in range(n)])\n", + "\n", + "def ones(n,m):\n", + " return matrix([[1.0 for _ in range(m)] for __ in range(n)])\n", + "\n", + "def eye(n):\n", + " return matrix([[0 if _ != __ else 1 for _ in range(n)] for __ in range(n)])" + ] + }, + { + "cell_type": "code", + "execution_count": 253, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[5, 5, 5, 5], [5, 5, 5, 5], [5, 5, 5, 5]]\n", + "[[0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0], [0.0, 0.0, 0.0, 0.0]]\n", + "[[1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0], [1.0, 1.0, 1.0, 1.0]]\n", + "[[1, 0, 0, 0, 0], [0, 1, 0, 0, 0], [0, 0, 1, 0, 0], [0, 0, 0, 1, 0], [0, 0, 0, 0, 1]]\n" + ] + } + ], + "source": [ + "print(constant(3,4,5))\n", + "print(zeros(3,4))\n", + "print(ones(3,4))\n", + "print(eye(5))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "4. Add the following member functions to your class. Make sure to appropriately test the dimensions of the matrices to make sure the operations are correct.\n", + " * `M.scalarmul(c)`: a matrix that is scalar product $cM$, where every element of $M$ is multiplied by $c$.\n", + " * `M.add(N)`: adds two matrices $M$ and $N$. Don’t forget to test that the sizes of the matrices are compatible for this and all other operations.\n", + " * `M.sub(N)`: subtracts two matrices $M$ and $N$.\n", + " * `M.mat_mult(N)`: returns a matrix that is the matrix product of two matrices $M$ and $N$.\n", + " * `M.element_mult(N)`: returns a matrix that is the element-wise product of two matrices $M$ and $N$.\n", + " * `M.equals(N)`: returns true/false if $M==N$." + ] + }, + { + "cell_type": "code", + "execution_count": 254, + "metadata": {}, + "outputs": [], + "source": [ + "def scalarmul(self, c):\n", + " n,m = self.shape()\n", + " M = matrix(n,m)\n", + " for _ in range(len(self._M)):\n", + " for __ in range(len(self._M[_])):\n", + " M._M[_][__] = self._M[_][__] * c\n", + " return M\n", + "def add(self, N):\n", + " n,m = self.shape()\n", + " M = matrix(n,m)\n", + " if self.shape() == N.shape():\n", + " for _ in range(n):\n", + " for __ in range(m):\n", + " M._M[_][__] = self._M[_][__] + N._M[_][__]\n", + " return M\n", + "def sub(self, N):\n", + " M = None\n", + " if self.shape() == N.shape():\n", + " n,m = self.shape()\n", + " M = matrix(n,m)\n", + " for _ in range(n):\n", + " for __ in range(m):\n", + " M._M[_][__] = self._M[_][__] - N._M[_][__]\n", + " return M\n", + "def mat_mult(self, N):\n", + " M = None\n", + " if len(self._M[0]) == len(N._M):\n", + " M = matrix(len(self._M), len(N._M[0]))\n", + " for i in range(len(self._M)):\n", + " for j in range(len(N._M[0])):\n", + " for k in range(len(N._M)):\n", + " M[i][j] += self._M[i][k] * N._M[k][j]\n", + " return M\n", + "def element_mult(self, N):\n", + " M = None\n", + " if self.shape() == N.shape():\n", + " n,m = self.shape()\n", + " M = matrix(n,m)\n", + " for _ in range(n):\n", + " for __ in range(m):\n", + " M._M[_][__] = self._M[_][__] * N._M[_][__]\n", + " return M\n", + "setattr(matrix, 'scalarmul', scalarmul)\n", + "setattr(matrix, 'add', add)\n", + "setattr(matrix, 'sub', sub)\n", + "setattr(matrix, 'mat_mult', mat_mult)\n", + "setattr(matrix, 'element_mult', element_mult)" + ] + }, + { + "cell_type": "code", + "execution_count": 255, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 3], [4, 5, 6]]\n", + "[[2, 4, 6], [8, 10, 12]]\n", + "[[4, 4, 4], [10, 10, 10]]\n", + "[[1, 1, 1], [2, 2, 2]]\n", + "[[1, 2, 3], [4, 5, 6]]\n", + "[[2, 6, 12], [0, 5, 12]]\n" + ] + } + ], + "source": [ + "M1 = matrix([[1,2,3],[4,5,6]])\n", + "print(M1)\n", + "print(M1.scalarmul(2))\n", + "print(M1.add(matrix([[3,2,1],[6,5,4]])))\n", + "print(M1.sub(matrix([[0,1,2],[2,3,4]])))\n", + "print(M1.mat_mult(eye(3)))\n", + "print(M1.element_mult(matrix([[2,3,4],[0,1,2]])))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "5. Overload python operators to appropriately use your functions in 4 and allow expressions like:\n", + " * 2*M\n", + " * M*2\n", + " * M+N\n", + " * M-N\n", + " * M*N\n", + " * M==N\n", + " * M=N\n" + ] + }, + { + "cell_type": "code", + "execution_count": 256, + "metadata": {}, + "outputs": [], + "source": [ + "def __mul__(self,o):\n", + " if isinstance(o, int) or isinstance(o, float):\n", + " return self.scalarmul(o)\n", + " elif len(self._M[0]) == len(o._M):\n", + " return self.mat_mult(o)\n", + " elif self.shape() == o.shape():\n", + " return self.element_mult(o)\n", + " else:\n", + " print(\"invalid __mul__ usage\")\n", + " return None\n", + "def __rmul__(self,o):\n", + " return self * o\n", + "def __add__(self,o):\n", + " if isinstance(o, matrix) and self.shape() == o.shape():\n", + " return self.add(o)\n", + " else:\n", + " print(\"invalid __add__ usage\")\n", + " return None\n", + "def __sub__(self,o):\n", + " if isinstance(o, matrix) and self.shape() == o.shape():\n", + " return self.sub(o)\n", + " else:\n", + " print(\"invalid __sub__ usage\")\n", + " return None\n", + "def __eq__(self,o):\n", + " if isinstance(o, matrix) and self.shape() == o.shape():\n", + " n,m = self.shape()\n", + " for i in range(n):\n", + " for j in range(m):\n", + " if self.to_list()[i][j] != o.to_list()[i][j]:\n", + " return False\n", + " return True\n", + " else:\n", + " return False\n", + "setattr(matrix, '__mul__', __mul__)\n", + "setattr(matrix, '__rmul__', __rmul__)\n", + "setattr(matrix, '__add__', __add__)\n", + "setattr(matrix, '__sub__', __sub__)\n", + "setattr(matrix, '__eq__', __eq__)" + ] + }, + { + "cell_type": "code", + "execution_count": 257, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 2, 3], [4, 5, 6]]\n", + "[[2, 4, 6], [8, 10, 12]]\n", + "[[2, 4, 6], [8, 10, 12]]\n", + "[[4, 4, 4], [10, 10, 10]]\n", + "[[1, 1, 1], [2, 2, 2]]\n", + "[[1, 2, 3], [4, 5, 6]]\n", + "[[2, 6, 12], [0, 5, 12]]\n", + "True\n" + ] + } + ], + "source": [ + "M1 = matrix([[1,2,3],[4,5,6]])\n", + "print(M1)\n", + "print(M1*2)\n", + "print(2*M1)\n", + "print(M1+matrix([[3,2,1],[6,5,4]]))\n", + "print(M1-matrix([[0,1,2],[2,3,4]]))\n", + "print(M1*eye(3))\n", + "print(M1*matrix([[2,3,4],[0,1,2]]))\n", + "print(M1==matrix([[1,2,3],[4,5,6]]))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Demonstrate the basic properties of matrices with your matrix class by creating two 2 by 2 example matrices using your Matrix class and illustrating the following:\n", + "\n", + "$$\n", + "(AB)C=A(BC)\n", + "$$\n", + "$$\n", + "A(B+C)=AB+AC\n", + "$$\n", + "$$\n", + "AB\\neq BA\n", + "$$\n", + "$$\n", + "AI=A\n", + "$$" + ] + }, + { + "cell_type": "code", + "execution_count": 258, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(AB)C: [[95, 118], [211, 262]]\n", + "A(BC): [[95, 118], [211, 262]]\n", + "A(B+C): [[23, 29], [51, 65]]\n", + "AB+AC: [[23, 29], [51, 65]]\n", + "AB: [[10, 13], [22, 29]]\n", + "BA: [[11, 16], [19, 28]]\n", + "AI: [[1, 2], [3, 4]]\n", + "A: [[1, 2], [3, 4]]\n" + ] + } + ], + "source": [ + "A = matrix([[1,2],[3,4]])\n", + "B = matrix([[2,3],[4,5]])\n", + "C = matrix([[3,4],[5,6]])\n", + "print(\"(AB)C: {}\".format((A*B)* C))\n", + "print(\"A(BC): {}\".format(A*(B*C)))\n", + "print(\"A(B+C): {}\".format(A*(B+C)))\n", + "print(\"AB+AC: {}\".format(A*B + A*C))\n", + "print(\"AB: {}\".format(A*B))\n", + "print(\"BA: {}\".format(B*A))\n", + "print(\"AI: {}\".format(A*eye(2)))\n", + "print(\"A: {}\".format(A))" + ] + }, + { + "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.7.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Labs/Lab-7/Data1401-Grades.csv b/Labs/Lab-7/Data1401-Grades.csv index ad6e2f6..126bd44 100644 --- a/Labs/Lab-7/Data1401-Grades.csv +++ b/Labs/Lab-7/Data1401-Grades.csv @@ -1,17 +1,17 @@ -l1_n,l1_1,12_n,l2_1,l2_2,l2_3,l2_4,l2_5,l2_6,l2_7,l3_n,l3_1,l3_2,l3_3,l3_4,l3_5,l3_6,l3_7,l3_8,l3_9,l3_10,l3_11,l3_12,l3_13,l3_14,l4_n,l4_1,l4_2,l4_3,l4_4,l4_5,l4_6,l4_7,l4_8,l4_9,l4_10,l4_11,q1_n,q1_1,e1_n,e1_1,e1_2,e1_3,e1_4,e1_5,e1_6,e1_7,e1_8,e1_9,e1_10,e1_11,e1_12,e1_13,e1_14,e1_15 -1,10,7,0,10,10,8,10,10,10,14,9,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,9.5,15,9,9,0,9,8,0,0,0,0,0,0,0,0,0,0 -1,10,7,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 -1,10,7,0,0,0,0,0,0,0,14,9,10,10,10,7,10,3,6,3,3,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,5,15,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0 -1,10,7,10,10,3,9.5,10,10,9.5,14,10,10,10,8,5,10,5,10,3,0,10,3,10,8,11,10,10,10,10,10,10,0,0,10,5,0,1,10,15,9,9,10,9,7,9,0,0,10,10,9,5,10,8,10 -1,10,7,10,10,9.5,0,10,10,0,14,9.5,0,0,10,0,10,5,10,7,0,10,6,10,0,11,10,10,6,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,5,0,7,0,3,3,3,0,3,0,0 -1,10,7,10,10,10,9.5,10,10,9.5,14,5,9.5,9.5,8,10,10,8,10,8,0,5,6,0,0,11,0,10,10,10,0,5,0,0,0,0,0,1,9.5,15,9,9,10,9,9,10,7,0,9,9,9,0,5,0,0 -1,10,7,10,10,0,5,10,10,9.5,14,9.5,10,10,8,10,8,9,0,0,0,0,0,0,0,11,0,10,10,0,0,10,0,0,0,0,0,1,10,15,9,9,10,9,0,0,0,0,0,0,0,0,0,0,0 -1,10,7,10,10,10,9.5,10,10,9.5,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,3,3,0,0,5,0,0,1,10,15,9,9,10,0,10,0,7,5,9,9,9,0,0,0,0 -1,10,7,0,10,9.5,0,10,10,0,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,5,3,0,3,10,7,0,1,9.5,15,9,9,10,5,10,0,9,9,9,9,9,10,5,0,0 -1,10,7,10,10,0,10,10,10,10,14,10,6,10,0,0,0,0,0,0,0,0,0,0,0,11,10,10,0,7,0,0,0,0,0,0,0,1,9.5,15,9,9,10,9,5,9,7,9,10,10,10,5,10,5,0 -1,10,7,10,10,0,0,10,10,7,14,10,10,10,10,7,10,6,3,10,10,10,10,10,10,11,10,10,10,10,10,5,10,10,10,10,10,1,0,15,9,9,9,9,9,10,9,9,10,10,10,10,10,5,10 -1,10,7,10,10,9.5,9.5,10,10,9.5,14,9.5,10,10,10,8,10,8,10,10,7,5,0,0,0,11,10,10,10,10,5,6,0,0,0,0,0,1,10,15,9,9,10,9,8,9,7,9,10,10,10,10,0,0,0 -1,10,7,10,10,5,9.5,10,10,9.5,14,5,9,9,10,7,10,10,10,10,7,10,3,5,10,11,0,0,0,0,0,0,0,0,0,0,0,1,10,15,9,9,9,8,7,10,0,9,10,9,10,9,5,0,0 -1,10,7,10,10,9.5,0,10,10,0,14,9.5,10,10,10,10,10,10,10,0,0,10,5,10,10,11,0,10,10,0,0,5,0,0,0,0,0,1,0,15,9,9,10,0,8,9,7,9,10,10,10,10,10,0,0 -1,10,7,10,10,9.5,9,10,10,9.5,14,10,10,10,10,10,10,9,10,3,0,3,3,5,2,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,9,9,10,5,5,0,0,10,10,10,10,0,10,5,10 -1,10,7,10,10,3,7,10,10,9,14,10,10,10,10,0,10,9,10,7,7,3,7,5,8,11,10,10,10,8,5,3,0,0,7,0,0,1,9.5,15,9,9,10,10,7,10,10,10,10,10,10,10,9,8,2 +l1_n,l1_1,l2_n,l2_1,l2_2,l2_3,l2_4,l2_5,l2_6,l2_7,l3_n,l3_1,l3_2,l3_3,l3_4,l3_5,l3_6,l3_7,l3_8,l3_9,l3_10,l3_11,l3_12,l3_13,l3_14,l4_n,l4_1,l4_2,l4_3,l4_4,l4_5,l4_6,l4_7,l4_8,l4_9,l4_10,l4_11,q1_n,q1_1,e1_n,e1_1,e1_2,e1_3,e1_4,e1_5,e1_6,e1_7,e1_8,e1_9,e1_10,e1_11,e1_12,e1_13,e1_14,e1_15 +1,10,7,0,10,10,8,10,10,10,14,9,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,9.5,15,9,9,0,9,8,0,0,0,0,0,0,0,0,0,0 +1,10,7,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +1,10,7,0,0,0,0,0,0,0,14,9,10,10,10,7,10,3,6,3,3,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,5,15,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0 +1,10,7,10,10,3,9.5,10,10,9.5,14,10,10,10,8,5,10,5,10,3,0,10,3,10,8,11,10,10,10,10,10,10,0,0,10,5,0,1,10,15,9,9,10,9,7,9,0,0,10,10,9,5,10,8,10 +1,10,7,10,10,9.5,0,10,10,0,14,9.5,0,0,10,0,10,5,10,7,0,10,6,10,0,11,10,10,6,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,5,0,7,0,3,3,3,0,3,0,0 +1,10,7,10,10,10,9.5,10,10,9.5,14,5,9.5,9.5,8,10,10,8,10,8,0,5,6,0,0,11,0,10,10,10,0,5,0,0,0,0,0,1,9.5,15,9,9,10,9,9,10,7,0,9,9,9,0,5,0,0 +1,10,7,10,10,0,5,10,10,9.5,14,9.5,10,10,8,10,8,9,0,0,0,0,0,0,0,11,0,10,10,0,0,10,0,0,0,0,0,1,10,15,9,9,10,9,0,0,0,0,0,0,0,0,0,0,0 +1,10,7,10,10,10,9.5,10,10,9.5,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,3,3,0,0,5,0,0,1,10,15,9,9,10,0,10,0,7,5,9,9,9,0,0,0,0 +1,10,7,0,10,9.5,0,10,10,0,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,5,3,0,3,10,7,0,1,9.5,15,9,9,10,5,10,0,9,9,9,9,9,10,5,0,0 +1,10,7,10,10,0,10,10,10,10,14,10,6,10,0,0,0,0,0,0,0,0,0,0,0,11,10,10,0,7,0,0,0,0,0,0,0,1,9.5,15,9,9,10,9,5,9,7,9,10,10,10,5,10,5,0 +1,10,7,10,10,0,0,10,10,7,14,10,10,10,10,7,10,6,3,10,10,10,10,10,10,11,10,10,10,10,10,5,10,10,10,10,10,1,0,15,9,9,9,9,9,10,9,9,10,10,10,10,10,5,10 +1,10,7,10,10,9.5,9.5,10,10,9.5,14,9.5,10,10,10,8,10,8,10,10,7,5,0,0,0,11,10,10,10,10,5,6,0,0,0,0,0,1,10,15,9,9,10,9,8,9,7,9,10,10,10,10,0,0,0 +1,10,7,10,10,5,9.5,10,10,9.5,14,5,9,9,10,7,10,10,10,10,7,10,3,5,10,11,0,0,0,0,0,0,0,0,0,0,0,1,10,15,9,9,9,8,7,10,0,9,10,9,10,9,5,0,0 +1,10,7,10,10,9.5,0,10,10,0,14,9.5,10,10,10,10,10,10,10,0,0,10,5,10,10,11,0,10,10,0,0,5,0,0,0,0,0,1,0,15,9,9,10,0,8,9,7,9,10,10,10,10,10,0,0 +1,10,7,10,10,9.5,9,10,10,9.5,14,10,10,10,10,10,10,9,10,3,0,3,3,5,2,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,9,9,10,5,5,0,0,10,10,10,10,0,10,5,10 +1,10,7,10,10,3,7,10,10,9,14,10,10,10,10,0,10,9,10,7,7,3,7,5,8,11,10,10,10,8,5,3,0,0,7,0,0,1,9.5,15,9,9,10,10,7,10,10,10,10,10,10,10,9,8,2 diff --git a/Labs/Lab-7/Lab-7-Copy1.ipynb b/Labs/Lab-7/Lab-7-Copy1.ipynb new file mode 100644 index 0000000..4a2a368 --- /dev/null +++ b/Labs/Lab-7/Lab-7-Copy1.ipynb @@ -0,0 +1,5127 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab 7\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-7/Lab-7.ipynb)\n", + "\n", + "Here are the \"Gradebook\" classes from lecture. For this lab, you will use these classes and are encouraged to modify them as you need." + ] + }, + { + "cell_type": "code", + "execution_count": 789, + "metadata": {}, + "outputs": [], + "source": [ + "import numpy as np\n", + "import math\n", + "\n", + "# Create some virtual classes\n", + "class base:\n", + " __name=\"\"\n", + " \n", + " def __init__(self,name):\n", + " self.__name=name\n", + "\n", + " def name(self):\n", + " return self.__name\n", + "\n", + "class data(base):\n", + " def __init__(self,name):\n", + " base.__init__(self,name)\n", + " \n", + "class alg(base):\n", + " def __init__(self,name):\n", + " base.__init__(self,name)" + ] + }, + { + "cell_type": "code", + "execution_count": 790, + "metadata": {}, + "outputs": [], + "source": [ + "class grade(data):\n", + " __value=0\n", + " __numerical=True\n", + " __gradebook_name=str()\n", + " __letter_grades=[\"F-\",\"F\",\"F+\",\"D-\",\"D\",\"D+\",\"C-\",\"C\",\"C+\",\"B-\",\"B\",\"B+\",\"A-\",\"A\",\"A+\"]\n", + " \n", + " def __init__(self,name,numerical=True,value=None):\n", + " if value:\n", + " if isinstance(value,(int,float)):\n", + " self.__numerical=True\n", + " elif isinstance(value,str):\n", + " self.__numerical=False\n", + " self.set(value)\n", + " else: \n", + " self.__numerical=numerical\n", + " self.__gradebook_name=name\n", + " data.__init__(self,name+\" Grade Algorithm\") \n", + "\n", + " def set(self,value):\n", + " if isinstance(value,(int,float)) and self.__numerical:\n", + " self.__value=value\n", + " elif isinstance(value,str) and not self.__numerical:\n", + " if value in self.__letter_grades:\n", + " self.__value=value\n", + " else:\n", + " print (self.name()+\" Error: Bad Grade.\")\n", + " raise Exception\n", + " \n", + " def value(self):\n", + " return self.__value\n", + " \n", + " def numerical(self):\n", + " return self.__numerical\n", + " \n", + " def gradebook_name(self):\n", + " return self.__gradebook_name\n", + " \n", + " def __str__(self):\n", + " return self.__gradebook_name+\": \"+str(self.__value)\n", + "\n", + "class student(data):\n", + " __id_number=0\n", + " __grades=dict()\n", + " \n", + " def __init__(self,first_name, last_name,id_number):\n", + " self.__id_number=id_number\n", + " self.__grades=dict()\n", + " data.__init__(self,first_name+\" \"+last_name+\" Student Data\")\n", + "\n", + " def add_grade(self,a_grade,overwrite=False):\n", + " if overwrite or not a_grade.gradebook_name() in self.__grades:\n", + " self.__grades[a_grade.gradebook_name()]=a_grade\n", + " else:\n", + " print (self.name()+\" Error Adding Grade \"+a_grade.name()+\". Grade already exists.\")\n", + " raise Exception\n", + "\n", + " def grades(self):\n", + " return self.__grades\n", + " \n", + " def id_number(self):\n", + " return self.__id_number\n", + " \n", + " def __getitem__(self,key):\n", + " return self.__grades[key]\n", + " \n", + " def print_grades(self):\n", + " for grade in self.__grades:\n", + " print (self.__grades[grade])\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 791, + "metadata": {}, + "outputs": [], + "source": [ + "class calculator(alg): \n", + " def __init__(self,name):\n", + " alg.__init__(self,name)\n", + "\n", + " def apply(self,a_grade_book):\n", + " raise NotImplementedError\n" + ] + }, + { + "cell_type": "code", + "execution_count": 792, + "metadata": {}, + "outputs": [], + "source": [ + "class grade_book(data):\n", + " # New member class to hold arbitrary data associated with the class\n", + "\n", + " __data=dict()\n", + " __students=dict()\n", + " \n", + " def __init__(self,name):\n", + " data.__init__(self,name+\" Course Grade Book\")\n", + " self.__students=dict()\n", + " self.__data=dict()\n", + " \n", + " # New method to access data\n", + " def __getitem__(self,key):\n", + " return self.__data[key]\n", + " \n", + " def data(self):\n", + " return self.__data\n", + " \n", + " def print_data(self):\n", + " for k,v in self.__data.items():\n", + " print (k,\":\",v)\n", + " \n", + " def print_students(self):\n", + " for k,a_student in self.__students.items():\n", + " print (k, a_student.name())\n", + " a_student.print_grades()\n", + " print (\"_______________________________________\")\n", + " \n", + " # New method to add data\n", + " def __setitem__(self, key, value):\n", + " self.__data[key] = value\n", + " \n", + " def add_student(self,a_student):\n", + " self.__students[a_student.id_number()]=a_student\n", + "\n", + " # New method to allow iterating over students\n", + " def get_students(self):\n", + " return self.__students\n", + " \n", + " def assign_grade(self,key,a_grade):\n", + " the_student=None\n", + " try:\n", + " the_student=self.__students[key]\n", + " except:\n", + " for id in self.__students:\n", + " if key == self.__students[id].name():\n", + " the_student=self.__students[id]\n", + " break\n", + " if the_student:\n", + " the_student.add_grade(a_grade)\n", + " else:\n", + " print (self.name()+\" Error: Did not find student.\")\n", + " \n", + " def apply_calculator(self,a_calculator,**kwargs):\n", + " a_calculator.apply(self,**kwargs)\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 793, + "metadata": {}, + "outputs": [], + "source": [ + "class uncurved_letter_grade_percent(calculator):\n", + " __grades_definition=[ (.97,\"A+\"),\n", + " (.93,\"A\"),\n", + " (.9,\"A-\"),\n", + " (.87,\"B+\"),\n", + " (.83,\"B\"),\n", + " (.8,\"B-\"),\n", + " (.77,\"C+\"),\n", + " (.73,\"C\"),\n", + " (.7,\"C-\"),\n", + " (.67,\"C+\"),\n", + " (.63,\"C\"),\n", + " (.6,\"C-\"),\n", + " (.57,\"F+\"),\n", + " (.53,\"F\"),\n", + " (0.,\"F-\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,grade_name,max_grade=100.):\n", + " self.__max_grade=max_grade\n", + " self.__grade_name=grade_name\n", + " calculator.__init__(self,\n", + " \"Uncurved Percent Based Grade Calculator \"+self.__grade_name+\" Max=\"+str(self.__max_grade))\n", + " \n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if grade_name:\n", + " pass\n", + " else:\n", + " grade_name=self.__grade_name\n", + " \n", + " \n", + " for k,a_student in a_grade_book.get_students().items():\n", + " a_grade=a_student[grade_name]\n", + "\n", + " if not a_grade.numerical():\n", + " print (self.name()+ \" Error: Did not get a numerical grade as input.\")\n", + " raise Exception\n", + " \n", + " percent=a_grade.value()/self.__max_grade\n", + " \n", + " for i,v in enumerate(self.__grades_definition):\n", + " if percent>=v[0]:\n", + " break\n", + " \n", + " a_student.add_grade(grade(grade_name+\" Letter\",value=self.__grades_definition[i][1]))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 794, + "metadata": {}, + "outputs": [], + "source": [ + "class mean_std_calculator(calculator):\n", + " def __init__(self,grade_name):\n", + " self.__grade_name = grade_name\n", + " calculator.__init__(self,\"Mean and Standard Deviation Calculator\")\n", + " \n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if not grade_name:\n", + " grade_name = self.__grade_name\n", + " \n", + " grades=list()\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " grades.append(a_student[grade_name].value())\n", + " \n", + " a_grade_book[grade_name+\" Mean\"] = np.mean(grades)\n", + " a_grade_book[grade_name+\" STD\"] = math.sqrt(np.var(grades))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "collapsed": true + }, + "source": [ + "## CSV Reader\n", + "\n", + "*Exercise 1*: The data for a class are stored in a \"camma separated values\" (CSV) file name `Data1401-Grades.csv` in the directory of this lab. You can see the contents using the `cat` shell command:" + ] + }, + { + "cell_type": "code", + "execution_count": 795, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "l1_n,l1_1,l2_n,l2_1,l2_2,l2_3,l2_4,l2_5,l2_6,l2_7,l3_n,l3_1,l3_2,l3_3,l3_4,l3_5,l3_6,l3_7,l3_8,l3_9,l3_10,l3_11,l3_12,l3_13,l3_14,l4_n,l4_1,l4_2,l4_3,l4_4,l4_5,l4_6,l4_7,l4_8,l4_9,l4_10,l4_11,q1_n,q1_1,e1_n,e1_1,e1_2,e1_3,e1_4,e1_5,e1_6,e1_7,e1_8,e1_9,e1_10,e1_11,e1_12,e1_13,e1_14,e1_15\n", + "1,10,7,0,10,10,8,10,10,10,14,9,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,9.5,15,9,9,0,9,8,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,0,0,0,0,0,0,0,14,9,10,10,10,7,10,3,6,3,3,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,5,15,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,10,10,3,9.5,10,10,9.5,14,10,10,10,8,5,10,5,10,3,0,10,3,10,8,11,10,10,10,10,10,10,0,0,10,5,0,1,10,15,9,9,10,9,7,9,0,0,10,10,9,5,10,8,10\n", + "1,10,7,10,10,9.5,0,10,10,0,14,9.5,0,0,10,0,10,5,10,7,0,10,6,10,0,11,10,10,6,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,5,0,7,0,3,3,3,0,3,0,0\n", + "1,10,7,10,10,10,9.5,10,10,9.5,14,5,9.5,9.5,8,10,10,8,10,8,0,5,6,0,0,11,0,10,10,10,0,5,0,0,0,0,0,1,9.5,15,9,9,10,9,9,10,7,0,9,9,9,0,5,0,0\n", + "1,10,7,10,10,0,5,10,10,9.5,14,9.5,10,10,8,10,8,9,0,0,0,0,0,0,0,11,0,10,10,0,0,10,0,0,0,0,0,1,10,15,9,9,10,9,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,10,10,10,9.5,10,10,9.5,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,3,3,0,0,5,0,0,1,10,15,9,9,10,0,10,0,7,5,9,9,9,0,0,0,0\n", + "1,10,7,0,10,9.5,0,10,10,0,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,5,3,0,3,10,7,0,1,9.5,15,9,9,10,5,10,0,9,9,9,9,9,10,5,0,0\n", + "1,10,7,10,10,0,10,10,10,10,14,10,6,10,0,0,0,0,0,0,0,0,0,0,0,11,10,10,0,7,0,0,0,0,0,0,0,1,9.5,15,9,9,10,9,5,9,7,9,10,10,10,5,10,5,0\n", + "1,10,7,10,10,0,0,10,10,7,14,10,10,10,10,7,10,6,3,10,10,10,10,10,10,11,10,10,10,10,10,5,10,10,10,10,10,1,0,15,9,9,9,9,9,10,9,9,10,10,10,10,10,5,10\n", + "1,10,7,10,10,9.5,9.5,10,10,9.5,14,9.5,10,10,10,8,10,8,10,10,7,5,0,0,0,11,10,10,10,10,5,6,0,0,0,0,0,1,10,15,9,9,10,9,8,9,7,9,10,10,10,10,0,0,0\n", + "1,10,7,10,10,5,9.5,10,10,9.5,14,5,9,9,10,7,10,10,10,10,7,10,3,5,10,11,0,0,0,0,0,0,0,0,0,0,0,1,10,15,9,9,9,8,7,10,0,9,10,9,10,9,5,0,0\n", + "1,10,7,10,10,9.5,0,10,10,0,14,9.5,10,10,10,10,10,10,10,0,0,10,5,10,10,11,0,10,10,0,0,5,0,0,0,0,0,1,0,15,9,9,10,0,8,9,7,9,10,10,10,10,10,0,0\n", + "1,10,7,10,10,9.5,9,10,10,9.5,14,10,10,10,10,10,10,9,10,3,0,3,3,5,2,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,9,9,10,5,5,0,0,10,10,10,10,0,10,5,10\n", + "1,10,7,10,10,3,7,10,10,9,14,10,10,10,10,0,10,9,10,7,7,3,7,5,8,11,10,10,10,8,5,3,0,0,7,0,0,1,9.5,15,9,9,10,10,7,10,10,10,10,10,10,10,9,8,2\n" + ] + } + ], + "source": [ + "!cat Data1401-Grades.csv " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "You will note that the first line has the names of the \"columns\" of data, and that subsequent lines (or \"rows\") have the data for each student, separated by cammas.\n", + "\n", + "Recalling that in lecture we created a file reader, create a CSV reader function that takes a filename as input and returns data structure(s) that store the data in the file. Note that you are not allowed to use a library. The point here is for *you* to write the CSV reader. Some options for your data structures (pick one):\n", + "\n", + "* A list of dictionaries, where each element of the list is corresponds to a row of data and the dictionaries are keyed by the column name. For example `data[5][\"l3_5\"]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* A list of lists (i.e. a 2-D array or matrix) and a dictionary, where each element of the \"matrix\" corresponds to a a specific grade for a specific student and the dictionary maps the name of the column to the column index. For example `data[5][column_names[\"l1_5\"]]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* A dictionary of lists, where each element of the dictionary corresponds to a column of data and the lists contain the data in that column. For example `data[\"l3_5\"][5]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* (Extra Credit) A class that simultaneously supports all of the above methods." + ] + }, + { + "cell_type": "code", + "execution_count": 796, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '8',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '10',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '0',\n", + " 'e1_4': '9',\n", + " 'e1_5': '8',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '0',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '0',\n", + " 'l2_6': '0',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '0',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '0',\n", + " 'e1_2': '0',\n", + " 'e1_3': '0',\n", + " 'e1_4': '0',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '0',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '0',\n", + " 'l2_6': '0',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '3',\n", + " 'l3_8': '6',\n", + " 'l3_9': '3',\n", + " 'l3_10': '3',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '5',\n", + " 'e1_2': '5',\n", + " 'e1_3': '5',\n", + " 'e1_4': '5',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '3',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '8',\n", + " 'l3_5': '5',\n", + " 'l3_6': '10',\n", + " 'l3_7': '5',\n", + " 'l3_8': '10',\n", + " 'l3_9': '3',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '3',\n", + " 'l3_13': '10',\n", + " 'l3_14': '8',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '10',\n", + " 'l4_6': '10',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '10',\n", + " 'l4_10': '5',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '7',\n", + " 'e1_6': '9',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '9',\n", + " 'e1_12': '5',\n", + " 'e1_13': '10',\n", + " 'e1_14': '8',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '10',\n", + " 'l3_7': '5',\n", + " 'l3_8': '10',\n", + " 'l3_9': '7',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '6',\n", + " 'l3_13': '10',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '6',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '0',\n", + " 'e1_2': '0',\n", + " 'e1_3': '0',\n", + " 'e1_4': '0',\n", + " 'e1_5': '5',\n", + " 'e1_6': '0',\n", + " 'e1_7': '7',\n", + " 'e1_8': '0',\n", + " 'e1_9': '3',\n", + " 'e1_10': '3',\n", + " 'e1_11': '3',\n", + " 'e1_12': '0',\n", + " 'e1_13': '3',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '5',\n", + " 'l3_2': '9.5',\n", + " 'l3_3': '9.5',\n", + " 'l3_4': '8',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '8',\n", + " 'l3_8': '10',\n", + " 'l3_9': '8',\n", + " 'l3_10': '0',\n", + " 'l3_11': '5',\n", + " 'l3_12': '6',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '0',\n", + " 'l4_6': '5',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '9',\n", + " 'e1_6': '10',\n", + " 'e1_7': '7',\n", + " 'e1_8': '0',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '0',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '8',\n", + " 'l3_5': '10',\n", + " 'l3_6': '8',\n", + " 'l3_7': '9',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '10',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '3',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '5',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '0',\n", + " 'e1_5': '10',\n", + " 'e1_6': '0',\n", + " 'e1_7': '7',\n", + " 'e1_8': '5',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '5',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '3',\n", + " 'l4_9': '10',\n", + " 'l4_10': '7',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '5',\n", + " 'e1_5': '10',\n", + " 'e1_6': '0',\n", + " 'e1_7': '9',\n", + " 'e1_8': '9',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '10',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '10',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '10',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '6',\n", + " 'l3_3': '10',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '0',\n", + " 'l4_4': '7',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '5',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '5',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '7',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '6',\n", + " 'l3_8': '3',\n", + " 'l3_9': '10',\n", + " 'l3_10': '10',\n", + " 'l3_11': '10',\n", + " 'l3_12': '10',\n", + " 'l3_13': '10',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '10',\n", + " 'l4_6': '5',\n", + " 'l4_7': '10',\n", + " 'l4_8': '10',\n", + " 'l4_9': '10',\n", + " 'l4_10': '10',\n", + " 'l4_11': '10',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '9',\n", + " 'e1_4': '9',\n", + " 'e1_5': '9',\n", + " 'e1_6': '10',\n", + " 'e1_7': '9',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '8',\n", + " 'l3_6': '10',\n", + " 'l3_7': '8',\n", + " 'l3_8': '10',\n", + " 'l3_9': '10',\n", + " 'l3_10': '7',\n", + " 'l3_11': '5',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '5',\n", + " 'l4_6': '6',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '8',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '5',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '5',\n", + " 'l3_2': '9',\n", + " 'l3_3': '9',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '10',\n", + " 'l3_8': '10',\n", + " 'l3_9': '10',\n", + " 'l3_10': '7',\n", + " 'l3_11': '10',\n", + " 'l3_12': '3',\n", + " 'l3_13': '5',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '9',\n", + " 'e1_4': '8',\n", + " 'e1_5': '7',\n", + " 'e1_6': '10',\n", + " 'e1_7': '0',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '9',\n", + " 'e1_11': '10',\n", + " 'e1_12': '9',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '10',\n", + " 'l3_8': '10',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '5',\n", + " 'l3_13': '10',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '5',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '0',\n", + " 'e1_5': '8',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '10',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '9',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '9',\n", + " 'l3_8': '10',\n", + " 'l3_9': '3',\n", + " 'l3_10': '0',\n", + " 'l3_11': '3',\n", + " 'l3_12': '3',\n", + " 'l3_13': '5',\n", + " 'l3_14': '2',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '5',\n", + " 'e1_5': '5',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '10',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '0',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '3',\n", + " 'l2_4': '7',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '10',\n", + " 'l3_7': '9',\n", + " 'l3_8': '10',\n", + " 'l3_9': '7',\n", + " 'l3_10': '7',\n", + " 'l3_11': '3',\n", + " 'l3_12': '7',\n", + " 'l3_13': '5',\n", + " 'l3_14': '8',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '8',\n", + " 'l4_5': '5',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '7',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '10',\n", + " 'e1_5': '7',\n", + " 'e1_6': '10',\n", + " 'e1_7': '10',\n", + " 'e1_8': '10',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '9',\n", + " 'e1_14': '8',\n", + " 'e1_15': '2'}]" + ] + }, + "execution_count": 796, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Your solution here.\n", + "\n", + "def cvs_reader(filename):\n", + " data=list() # if you choose first option\n", + " f=open(filename,\"r\")\n", + " columns = f.readline().rstrip().split(\",\")\n", + " \n", + " for line in f:\n", + " row = dict()\n", + " l = line.rstrip()\n", + " items = l.split(\",\")\n", + " for i, item in enumerate(items):\n", + " row[columns[i]] = item\n", + " data.append(row)\n", + " f.close()\n", + " return data\n", + "\n", + "cvs_reader(\"Data1401-Grades.csv\")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Creating a Gradebook\n", + "\n", + "*Exercise 2:* In lecture we used pandas to read the CSV file and create the grade book. The example below works for the CSV file for this lab. Modify the code below to use your CSV reader instead." + ] + }, + { + "cell_type": "code", + "execution_count": 797, + "metadata": {}, + "outputs": [], + "source": [ + "class_data=cvs_reader(\"Data1401-Grades.csv\")\n", + "\n", + "a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + " for k in class_data[student_i].keys():\n", + " a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", + "\n", + " a_grade_book.add_student(a_student_0)\n", + " " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Grade Summing\n", + "\n", + "*Exercise 3:* In lectre we will change the design of our algorithm classes and then update the `uncurved_letter_grade_percent` calculator. In lecture we also created a `grade_summer` calcuator that takes a prefix (for example `e1_` and a number `n`) and sums all grades starting with that prefix up to `n` and creates a new sum grade. Update this calculator (below) to the new design of our algorithm classes. Test your updated calculator by using it to sum the grades for all labs, quizzes, and exams of each student." + ] + }, + { + "cell_type": "code", + "execution_count": 798, + "metadata": {}, + "outputs": [], + "source": [ + "# Note this is the OLD design... you will need to modify it.\n", + "\n", + "class summary_calculator(alg): \n", + " def __init__(self,name):\n", + " alg.__init__(self,name)\n", + "\n", + " def apply(self,a_student):\n", + " raise NotImplementedError\n", + "\n", + "class grade_summer(calculator):\n", + " def __init__(self,prefix,n):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " calculator.__init__(self,\"Sum Grades\")\n", + " \n", + " def apply(self,a_gradebook,**kwargs):\n", + " labels=[self.__prefix + str(x) for x in range(1,self.__n)]\n", + " \n", + " for k,a_student in a_grade_book.get_students().items(): \n", + "\n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", + "\n", + " a_student.add_grade(grade(self.__prefix+\"sum\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 799, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['e1_', 'l1_', 'l2_', 'l3_', 'l4_', 'q1_']\n" + ] + } + ], + "source": [ + "a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + " for k in class_data[student_i].keys():\n", + " a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", + "\n", + " a_grade_book.add_student(a_student_0)\n", + "#print(class_data)\n", + "prefixes=sorted(list(set([k.split(\"_\")[0] + \"_\" for k in class_data[0].keys()])))\n", + "#labels=[self.__prefix+str(x) for x in range(1,self.__n)]\n", + "print(prefixes)\n", + "for j, prefix in enumerate(prefixes):\n", + " a_grade_book.apply_calculator(grade_summer(prefix, int(list(a_grade_book.get_students().values())[j][prefix+\"n\"].value())+1))" + ] + }, + { + "cell_type": "code", + "execution_count": 800, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_ [35.0, 0, 20.0, 115.0, 24.0, 95.0, 37.0, 77.0, 103.0, 117.0, 138.0, 110.0, 104.0, 111.0, 103.0, 134.0]\n", + "l1_ [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_ [58.0, 0, 0, 62.0, 49.5, 69.0, 54.5, 69.0, 39.5, 60.0, 47.0, 68.5, 64.0, 49.5, 68.0, 59.0]\n", + "l3_ [9.0, 0, 71.0, 102.0, 77.5, 89.0, 64.5, 40.0, 40.0, 26.0, 126.0, 97.5, 115.0, 114.5, 95.0, 106.0]\n", + "l4_ [0, 0, 0, 75.0, 26.0, 35.0, 30.0, 51.0, 68.0, 27.0, 105.0, 51.0, 0, 25.0, 0, 53.0]\n", + "q1_ [9.5, 0, 5.0, 10.0, 0, 9.5, 10.0, 10.0, 9.5, 9.5, 0, 10.0, 10.0, 0, 0, 9.5]\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " print(prefix,list(a_student[prefix+\"sum\"].value() for k,a_student in a_grade_book.get_students().items()))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Curving Grades\n", + "\n", + "*Exercise 4:* Use the `mean_std_calculator` above to calculate the mean and standard deviation for every lab, quiz, and exam in the class. Add a new print function to the `grade_book` class to print out such information in a nice way, and use this function to show your results.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 801, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_sum Mean : 82.6875\n", + "e1_sum STD : 42.937045121316864\n", + "l1_sum Mean : 10.0\n", + "l1_sum STD : 0.0\n", + "l2_sum Mean : 51.09375\n", + "l2_sum STD : 21.05663401252679\n", + "l3_sum Mean : 73.3125\n", + "l3_sum STD : 38.301792957379945\n", + "l4_sum Mean : 34.125\n", + "l4_sum STD : 30.421774685248064\n", + "q1_sum Mean : 6.40625\n", + "q1_sum STD : 4.469405546322688\n" + ] + } + ], + "source": [ + "# Your solution here\n", + "prefixes=sorted(list(set([k.split(\"_\")[0] + \"_\" for k in class_data[0].keys()])))\n", + "for prefix in prefixes:\n", + " a_grade_book.apply_calculator(mean_std_calculator(grade_name=prefix+\"sum\"))\n", + "a_grade_book.print_data()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Exercise 5:* In lecture we will change the design of our algorithms classes and then update the `uncurved_letter_grade_percent` calculator. Do the same for the `curved_letter_grade` calculator below and by curving all the lab, quiz, and exam grades." + ] + }, + { + "cell_type": "code", + "execution_count": 802, + "metadata": {}, + "outputs": [], + "source": [ + "class curved_letter_grade(calculator):\n", + " __grades_definition=[ (.97,\"A+\"),\n", + " (.93,\"A\"),\n", + " (.9,\"A-\"),\n", + " (.87,\"B+\"),\n", + " (.83,\"B\"),\n", + " (.8,\"B-\"),\n", + " (.77,\"C+\"),\n", + " (.73,\"C\"),\n", + " (.7,\"C-\"),\n", + " (.67,\"C+\"),\n", + " (.63,\"C\"),\n", + " (.6,\"C-\"),\n", + " (.57,\"F+\"),\n", + " (.53,\"F\"),\n", + " (0.,\"F-\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,grade_name,mean,std,max_grade=100.):\n", + " self.__max_grade=max_grade\n", + " self.__mean=mean\n", + " self.__std=std\n", + " self.__grade_name=grade_name\n", + " calculator.__init__(self,\n", + " \"Curved Percent Based Grade Calculator \"+self.__grade_name+ \\\n", + " \" Mean=\"+str(self.__mean)+\\\n", + " \" STD=\"+str(self.__std)+\\\n", + " \" Max=\"+str(self.__max_grade))\n", + " \n", + "\n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if grade_name:\n", + " pass\n", + " else:\n", + " grade_name=self.__grade_name\n", + " \n", + " for k,a_student in a_grade_book.get_students().items():\n", + " a_grade = a_student[grade_name]\n", + "\n", + " if not a_grade.numerical():\n", + " print(self.name()+\"Error: Did not get a numerical grade as input.\")\n", + " raise Exception\n", + "\n", + " # Rescale the grade\n", + " scaled_percent=1\n", + " if self.__std != 0:\n", + " percent=a_grade.value()/self.__max_grade\n", + " shift_to_zero=percent-(self.__mean/self.__max_grade)\n", + " scale_std=0.1*shift_to_zero/(self.__std/self.__max_grade)\n", + " scaled_percent=scale_std+0.8\n", + "\n", + " for i,v in enumerate(self.__grades_definition):\n", + " if scaled_percent>=v[0]:\n", + " break\n", + "\n", + " overwrite = kwargs[\"overwrite\"] if \"overwrite\" in kwargs else False\n", + " #g = grade(grade_name+\" Letter\",value=self.__grades_definition[i][1])\n", + " a_student.add_grade(grade(grade_name+\" Letter\",value=self.__grades_definition[i][1]),overwrite=overwrite)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 803, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F+\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: C\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F+\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F\n", + "q1_sum Letter: F-\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " grade_name = prefix+\"sum\"\n", + " a_grade_book.apply_calculator(uncurved_letter_grade_percent(grade_name,max_grade=100))\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": 804, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: C-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: A\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B-\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: A-\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " grade_name = prefix+\"sum\"\n", + " a_grade_book.apply_calculator(curved_letter_grade(grade_name,\n", + " a_grade_book[grade_name+\" Mean\"],\n", + " a_grade_book[grade_name+\" STD\"]),\n", + " overwrite=True)\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Final Course Grade\n", + "\n", + "*Exercise 6:* Write a new calculator that sums grades with a prefix, as in the `grade_summer` calculator, but drops `n` lowest grades. Apply the algorithm to drop the lowest lab grade in the data.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 787, + "metadata": {}, + "outputs": [], + "source": [ + "# Your solution here\n", + "class grade_dropper(calculator):\n", + " def __init__(self,prefix,n):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " calculator.__init__(self,\"Final Course Grades\")\n", + " \n", + " def apply(self,a_gradebook,**kwargs):\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " labels=list(filter(lambda x: \n", + " self.__prefix in x, \n", + " a_student.grades().keys()))\n", + " print(labels)\n", + " grade_sum=0.\n", + " grades=list()\n", + " for label in labels:\n", + " if '_' in label and isinstance(a_student[label].value(),(int,float)):\n", + " grades.append(a_student[label].value())\n", + " grades = sorted(grades)\n", + " if len(grades) > self.__n:\n", + " grade_sum = sum(grades[self.__n:])\n", + " else:\n", + " grade_sum = sum(grades)\n", + "# grade_sum = sum(grades)\n", + "\n", + " a_student.add_grade(grade(self.__prefix+\" dropped sum\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 805, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['l1_sum', 'l2_sum', 'l3_sum', 'l4_sum', 'l1_sum Letter', 'l2_sum Letter', 'l3_sum Letter', 'l4_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 58.0\n", + "l3_sum dropped sum: 9.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: C-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 0\n", + "l3_sum dropped sum: 0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 0\n", + "l3_sum dropped sum: 71.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: A\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 62.0\n", + "l3_sum dropped sum: 102.0\n", + "l4_sum dropped sum: 75.0\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 49.5\n", + "l3_sum dropped sum: 77.5\n", + "l4_sum dropped sum: 26.0\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B-\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 69.0\n", + "l3_sum dropped sum: 89.0\n", + "l4_sum dropped sum: 35.0\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 54.5\n", + "l3_sum dropped sum: 64.5\n", + "l4_sum dropped sum: 30.0\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 69.0\n", + "l3_sum dropped sum: 40.0\n", + "l4_sum dropped sum: 51.0\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: A-\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 39.5\n", + "l3_sum dropped sum: 40.0\n", + "l4_sum dropped sum: 68.0\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 60.0\n", + "l3_sum dropped sum: 26.0\n", + "l4_sum dropped sum: 27.0\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 47.0\n", + "l3_sum dropped sum: 126.0\n", + "l4_sum dropped sum: 105.0\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 68.5\n", + "l3_sum dropped sum: 97.5\n", + "l4_sum dropped sum: 51.0\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 64.0\n", + "l3_sum dropped sum: 115.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 49.5\n", + "l3_sum dropped sum: 114.5\n", + "l4_sum dropped sum: 25.0\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 68.0\n", + "l3_sum dropped sum: 95.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 59.0\n", + "l3_sum dropped sum: 106.0\n", + "l4_sum dropped sum: 53.0\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "# a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "# for student_i in range(len(class_data)):\n", + "# a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + "# for k in class_data[student_i].keys():\n", + "# a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", + "\n", + "# a_grade_book.add_student(a_student_0)\n", + "lab_prefixes = list(filter(lambda x: 'l' in x and 'sum' in x, list(a_grade_book.get_students().values())[0].grades().keys()))\n", + "print(lab_prefixes)\n", + "\n", + "for prefix in lab_prefixes:\n", + " if ' ' not in prefix:\n", + " a_grade_book.apply_calculator(grade_dropper(prefix,1), overwrite=True)\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "*Exercise 7*: Write a new calculator that creates a new letter grade based on a weighted average of letter grades, by assigning the following numerical values to letter grades:" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "GradeMap={\"A+\":12,\n", + " \"A\":11,\n", + " \"A-\":10,\n", + " \"B+\":9,\n", + " \"B\":8,\n", + " \"B-\":7,\n", + " \"C+\":6,\n", + " \"C\":5,\n", + " \"C-\":4,\n", + " \"D+\":3,\n", + " \"D\":2,\n", + " \"D-\":1,\n", + " \"F\":0}" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Test you calculator by applying the weights from the syllabus of this course and computing everyone's grade in the course." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Your solution here" + ] + } + ], + "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.2" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Labs/Lab-7/Lab-7.ipynb b/Labs/Lab-7/Lab-7.ipynb index 5a9197d..4a2a368 100644 --- a/Labs/Lab-7/Lab-7.ipynb +++ b/Labs/Lab-7/Lab-7.ipynb @@ -13,7 +13,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 789, "metadata": {}, "outputs": [], "source": [ @@ -41,7 +41,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 790, "metadata": {}, "outputs": [], "source": [ @@ -101,6 +101,9 @@ " print (self.name()+\" Error Adding Grade \"+a_grade.name()+\". Grade already exists.\")\n", " raise Exception\n", "\n", + " def grades(self):\n", + " return self.__grades\n", + " \n", " def id_number(self):\n", " return self.__id_number\n", " \n", @@ -115,7 +118,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 791, "metadata": {}, "outputs": [], "source": [ @@ -129,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 792, "metadata": {}, "outputs": [], "source": [ @@ -147,7 +150,20 @@ " # New method to access data\n", " def __getitem__(self,key):\n", " return self.__data[key]\n", - " \n", + " \n", + " def data(self):\n", + " return self.__data\n", + " \n", + " def print_data(self):\n", + " for k,v in self.__data.items():\n", + " print (k,\":\",v)\n", + " \n", + " def print_students(self):\n", + " for k,a_student in self.__students.items():\n", + " print (k, a_student.name())\n", + " a_student.print_grades()\n", + " print (\"_______________________________________\")\n", + " \n", " # New method to add data\n", " def __setitem__(self, key, value):\n", " self.__data[key] = value\n", @@ -181,7 +197,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 793, "metadata": {}, "outputs": [], "source": [ @@ -217,7 +233,7 @@ " grade_name=self.__grade_name\n", " \n", " \n", - " for k,a_student in a_grade_book.get_students().iteritems():\n", + " for k,a_student in a_grade_book.get_students().items():\n", " a_grade=a_student[grade_name]\n", "\n", " if not a_grade.numerical():\n", @@ -236,17 +252,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 794, "metadata": {}, "outputs": [], "source": [ "class mean_std_calculator(calculator):\n", - " def __init__(self):\n", + " def __init__(self,grade_name):\n", + " self.__grade_name = grade_name\n", " calculator.__init__(self,\"Mean and Standard Deviation Calculator\")\n", " \n", - " def apply(self,a_grade_book,grade_name,**kwargs):\n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if not grade_name:\n", + " grade_name = self.__grade_name\n", + " \n", " grades=list()\n", - " for k,a_student in a_grade_book.get_students().iteritems():\n", + " for k,a_student in a_grade_book.get_students().items():\n", " grades.append(a_student[grade_name].value())\n", " \n", " a_grade_book[grade_name+\" Mean\"] = np.mean(grades)\n", @@ -266,47 +286,30 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 795, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "l1_n,l1_1,12_n,l2_1,l2_2,l2_3,l2_4,l2_5,l2_6,l2_7,l3_n,l3_1,l3_2,l3_3,l3_4,l3_5,l3_6,l3_7,l3_8,l3_9,l3_10,l3_11,l3_12,l3_13,l3_14,l4_n,l4_1,l4_2,l4_3,l4_4,l4_5,l4_6,l4_7,l4_8,l4_9,l4_10,l4_11,q1_n,q1_1,e1_n,e1_1,e1_2,e1_3,e1_4,e1_5,e1_6,e1_7,e1_8,e1_9,e1_10,e1_11,e1_12,e1_13,e1_14,e1_15\r", - "\r\n", - "1,10,7,0,10,10,8,10,10,10,14,9,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,9.5,15,9,9,0,9,8,0,0,0,0,0,0,0,0,0,0\r", - "\r\n", - "1,10,7,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\r", - "\r\n", - "1,10,7,0,0,0,0,0,0,0,14,9,10,10,10,7,10,3,6,3,3,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,5,15,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0\r", - "\r\n", - "1,10,7,10,10,3,9.5,10,10,9.5,14,10,10,10,8,5,10,5,10,3,0,10,3,10,8,11,10,10,10,10,10,10,0,0,10,5,0,1,10,15,9,9,10,9,7,9,0,0,10,10,9,5,10,8,10\r", - "\r\n", - "1,10,7,10,10,9.5,0,10,10,0,14,9.5,0,0,10,0,10,5,10,7,0,10,6,10,0,11,10,10,6,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,5,0,7,0,3,3,3,0,3,0,0\r", - "\r\n", - "1,10,7,10,10,10,9.5,10,10,9.5,14,5,9.5,9.5,8,10,10,8,10,8,0,5,6,0,0,11,0,10,10,10,0,5,0,0,0,0,0,1,9.5,15,9,9,10,9,9,10,7,0,9,9,9,0,5,0,0\r", - "\r\n", - "1,10,7,10,10,0,5,10,10,9.5,14,9.5,10,10,8,10,8,9,0,0,0,0,0,0,0,11,0,10,10,0,0,10,0,0,0,0,0,1,10,15,9,9,10,9,0,0,0,0,0,0,0,0,0,0,0\r", - "\r\n", - "1,10,7,10,10,10,9.5,10,10,9.5,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,3,3,0,0,5,0,0,1,10,15,9,9,10,0,10,0,7,5,9,9,9,0,0,0,0\r", - "\r\n", - "1,10,7,0,10,9.5,0,10,10,0,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,5,3,0,3,10,7,0,1,9.5,15,9,9,10,5,10,0,9,9,9,9,9,10,5,0,0\r", - "\r\n", - "1,10,7,10,10,0,10,10,10,10,14,10,6,10,0,0,0,0,0,0,0,0,0,0,0,11,10,10,0,7,0,0,0,0,0,0,0,1,9.5,15,9,9,10,9,5,9,7,9,10,10,10,5,10,5,0\r", - "\r\n", - "1,10,7,10,10,0,0,10,10,7,14,10,10,10,10,7,10,6,3,10,10,10,10,10,10,11,10,10,10,10,10,5,10,10,10,10,10,1,0,15,9,9,9,9,9,10,9,9,10,10,10,10,10,5,10\r", - "\r\n", - "1,10,7,10,10,9.5,9.5,10,10,9.5,14,9.5,10,10,10,8,10,8,10,10,7,5,0,0,0,11,10,10,10,10,5,6,0,0,0,0,0,1,10,15,9,9,10,9,8,9,7,9,10,10,10,10,0,0,0\r", - "\r\n", - "1,10,7,10,10,5,9.5,10,10,9.5,14,5,9,9,10,7,10,10,10,10,7,10,3,5,10,11,0,0,0,0,0,0,0,0,0,0,0,1,10,15,9,9,9,8,7,10,0,9,10,9,10,9,5,0,0\r", - "\r\n", - "1,10,7,10,10,9.5,0,10,10,0,14,9.5,10,10,10,10,10,10,10,0,0,10,5,10,10,11,0,10,10,0,0,5,0,0,0,0,0,1,0,15,9,9,10,0,8,9,7,9,10,10,10,10,10,0,0\r", - "\r\n", - "1,10,7,10,10,9.5,9,10,10,9.5,14,10,10,10,10,10,10,9,10,3,0,3,3,5,2,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,9,9,10,5,5,0,0,10,10,10,10,0,10,5,10\r", - "\r\n", - "1,10,7,10,10,3,7,10,10,9,14,10,10,10,10,0,10,9,10,7,7,3,7,5,8,11,10,10,10,8,5,3,0,0,7,0,0,1,9.5,15,9,9,10,10,7,10,10,10,10,10,10,10,9,8,2\r", - "\r\n" + "l1_n,l1_1,l2_n,l2_1,l2_2,l2_3,l2_4,l2_5,l2_6,l2_7,l3_n,l3_1,l3_2,l3_3,l3_4,l3_5,l3_6,l3_7,l3_8,l3_9,l3_10,l3_11,l3_12,l3_13,l3_14,l4_n,l4_1,l4_2,l4_3,l4_4,l4_5,l4_6,l4_7,l4_8,l4_9,l4_10,l4_11,q1_n,q1_1,e1_n,e1_1,e1_2,e1_3,e1_4,e1_5,e1_6,e1_7,e1_8,e1_9,e1_10,e1_11,e1_12,e1_13,e1_14,e1_15\n", + "1,10,7,0,10,10,8,10,10,10,14,9,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,9.5,15,9,9,0,9,8,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,0,0,0,0,0,0,0,14,0,0,0,0,0,0,0,0,0,0,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,0,0,0,0,0,0,0,14,9,10,10,10,7,10,3,6,3,3,0,0,0,0,11,0,0,0,0,0,0,0,0,0,0,0,1,5,15,5,5,5,5,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,10,10,3,9.5,10,10,9.5,14,10,10,10,8,5,10,5,10,3,0,10,3,10,8,11,10,10,10,10,10,10,0,0,10,5,0,1,10,15,9,9,10,9,7,9,0,0,10,10,9,5,10,8,10\n", + "1,10,7,10,10,9.5,0,10,10,0,14,9.5,0,0,10,0,10,5,10,7,0,10,6,10,0,11,10,10,6,0,0,0,0,0,0,0,0,1,0,15,0,0,0,0,5,0,7,0,3,3,3,0,3,0,0\n", + "1,10,7,10,10,10,9.5,10,10,9.5,14,5,9.5,9.5,8,10,10,8,10,8,0,5,6,0,0,11,0,10,10,10,0,5,0,0,0,0,0,1,9.5,15,9,9,10,9,9,10,7,0,9,9,9,0,5,0,0\n", + "1,10,7,10,10,0,5,10,10,9.5,14,9.5,10,10,8,10,8,9,0,0,0,0,0,0,0,11,0,10,10,0,0,10,0,0,0,0,0,1,10,15,9,9,10,9,0,0,0,0,0,0,0,0,0,0,0\n", + "1,10,7,10,10,10,9.5,10,10,9.5,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,3,3,0,0,5,0,0,1,10,15,9,9,10,0,10,0,7,5,9,9,9,0,0,0,0\n", + "1,10,7,0,10,9.5,0,10,10,0,14,10,10,10,10,0,0,0,0,0,0,0,0,0,0,11,10,10,10,10,5,3,0,3,10,7,0,1,9.5,15,9,9,10,5,10,0,9,9,9,9,9,10,5,0,0\n", + "1,10,7,10,10,0,10,10,10,10,14,10,6,10,0,0,0,0,0,0,0,0,0,0,0,11,10,10,0,7,0,0,0,0,0,0,0,1,9.5,15,9,9,10,9,5,9,7,9,10,10,10,5,10,5,0\n", + "1,10,7,10,10,0,0,10,10,7,14,10,10,10,10,7,10,6,3,10,10,10,10,10,10,11,10,10,10,10,10,5,10,10,10,10,10,1,0,15,9,9,9,9,9,10,9,9,10,10,10,10,10,5,10\n", + "1,10,7,10,10,9.5,9.5,10,10,9.5,14,9.5,10,10,10,8,10,8,10,10,7,5,0,0,0,11,10,10,10,10,5,6,0,0,0,0,0,1,10,15,9,9,10,9,8,9,7,9,10,10,10,10,0,0,0\n", + "1,10,7,10,10,5,9.5,10,10,9.5,14,5,9,9,10,7,10,10,10,10,7,10,3,5,10,11,0,0,0,0,0,0,0,0,0,0,0,1,10,15,9,9,9,8,7,10,0,9,10,9,10,9,5,0,0\n", + "1,10,7,10,10,9.5,0,10,10,0,14,9.5,10,10,10,10,10,10,10,0,0,10,5,10,10,11,0,10,10,0,0,5,0,0,0,0,0,1,0,15,9,9,10,0,8,9,7,9,10,10,10,10,10,0,0\n", + "1,10,7,10,10,9.5,9,10,10,9.5,14,10,10,10,10,10,10,9,10,3,0,3,3,5,2,11,0,0,0,0,0,0,0,0,0,0,0,1,0,15,9,9,10,5,5,0,0,10,10,10,10,0,10,5,10\n", + "1,10,7,10,10,3,7,10,10,9,14,10,10,10,10,0,10,9,10,7,7,3,7,5,8,11,10,10,10,8,5,3,0,0,7,0,0,1,9.5,15,9,9,10,10,7,10,10,10,10,10,10,10,9,8,2\n" ] } ], @@ -333,16 +336,918 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 796, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "[{'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '8',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '10',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '0',\n", + " 'e1_4': '9',\n", + " 'e1_5': '8',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '0',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '0',\n", + " 'l2_6': '0',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '0',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '0',\n", + " 'e1_2': '0',\n", + " 'e1_3': '0',\n", + " 'e1_4': '0',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '0',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '0',\n", + " 'l2_6': '0',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '3',\n", + " 'l3_8': '6',\n", + " 'l3_9': '3',\n", + " 'l3_10': '3',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '5',\n", + " 'e1_2': '5',\n", + " 'e1_3': '5',\n", + " 'e1_4': '5',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '3',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '8',\n", + " 'l3_5': '5',\n", + " 'l3_6': '10',\n", + " 'l3_7': '5',\n", + " 'l3_8': '10',\n", + " 'l3_9': '3',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '3',\n", + " 'l3_13': '10',\n", + " 'l3_14': '8',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '10',\n", + " 'l4_6': '10',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '10',\n", + " 'l4_10': '5',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '7',\n", + " 'e1_6': '9',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '9',\n", + " 'e1_12': '5',\n", + " 'e1_13': '10',\n", + " 'e1_14': '8',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '0',\n", + " 'l3_3': '0',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '10',\n", + " 'l3_7': '5',\n", + " 'l3_8': '10',\n", + " 'l3_9': '7',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '6',\n", + " 'l3_13': '10',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '6',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '0',\n", + " 'e1_2': '0',\n", + " 'e1_3': '0',\n", + " 'e1_4': '0',\n", + " 'e1_5': '5',\n", + " 'e1_6': '0',\n", + " 'e1_7': '7',\n", + " 'e1_8': '0',\n", + " 'e1_9': '3',\n", + " 'e1_10': '3',\n", + " 'e1_11': '3',\n", + " 'e1_12': '0',\n", + " 'e1_13': '3',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '5',\n", + " 'l3_2': '9.5',\n", + " 'l3_3': '9.5',\n", + " 'l3_4': '8',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '8',\n", + " 'l3_8': '10',\n", + " 'l3_9': '8',\n", + " 'l3_10': '0',\n", + " 'l3_11': '5',\n", + " 'l3_12': '6',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '0',\n", + " 'l4_6': '5',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '9',\n", + " 'e1_6': '10',\n", + " 'e1_7': '7',\n", + " 'e1_8': '0',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '0',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '8',\n", + " 'l3_5': '10',\n", + " 'l3_6': '8',\n", + " 'l3_7': '9',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '10',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '0',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '0',\n", + " 'e1_9': '0',\n", + " 'e1_10': '0',\n", + " 'e1_11': '0',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '10',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '3',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '5',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '0',\n", + " 'e1_5': '10',\n", + " 'e1_6': '0',\n", + " 'e1_7': '7',\n", + " 'e1_8': '5',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '0',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '0',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '5',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '3',\n", + " 'l4_9': '10',\n", + " 'l4_10': '7',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '5',\n", + " 'e1_5': '10',\n", + " 'e1_6': '0',\n", + " 'e1_7': '9',\n", + " 'e1_8': '9',\n", + " 'e1_9': '9',\n", + " 'e1_10': '9',\n", + " 'e1_11': '9',\n", + " 'e1_12': '10',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '10',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '10',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '6',\n", + " 'l3_3': '10',\n", + " 'l3_4': '0',\n", + " 'l3_5': '0',\n", + " 'l3_6': '0',\n", + " 'l3_7': '0',\n", + " 'l3_8': '0',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '0',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '0',\n", + " 'l4_4': '7',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '5',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '5',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '0',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '7',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '6',\n", + " 'l3_8': '3',\n", + " 'l3_9': '10',\n", + " 'l3_10': '10',\n", + " 'l3_11': '10',\n", + " 'l3_12': '10',\n", + " 'l3_13': '10',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '10',\n", + " 'l4_6': '5',\n", + " 'l4_7': '10',\n", + " 'l4_8': '10',\n", + " 'l4_9': '10',\n", + " 'l4_10': '10',\n", + " 'l4_11': '10',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '9',\n", + " 'e1_4': '9',\n", + " 'e1_5': '9',\n", + " 'e1_6': '10',\n", + " 'e1_7': '9',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '8',\n", + " 'l3_6': '10',\n", + " 'l3_7': '8',\n", + " 'l3_8': '10',\n", + " 'l3_9': '10',\n", + " 'l3_10': '7',\n", + " 'l3_11': '5',\n", + " 'l3_12': '0',\n", + " 'l3_13': '0',\n", + " 'l3_14': '0',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '10',\n", + " 'l4_5': '5',\n", + " 'l4_6': '6',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '9',\n", + " 'e1_5': '8',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '0',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '5',\n", + " 'l2_4': '9.5',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '5',\n", + " 'l3_2': '9',\n", + " 'l3_3': '9',\n", + " 'l3_4': '10',\n", + " 'l3_5': '7',\n", + " 'l3_6': '10',\n", + " 'l3_7': '10',\n", + " 'l3_8': '10',\n", + " 'l3_9': '10',\n", + " 'l3_10': '7',\n", + " 'l3_11': '10',\n", + " 'l3_12': '3',\n", + " 'l3_13': '5',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '10',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '9',\n", + " 'e1_4': '8',\n", + " 'e1_5': '7',\n", + " 'e1_6': '10',\n", + " 'e1_7': '0',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '9',\n", + " 'e1_11': '10',\n", + " 'e1_12': '9',\n", + " 'e1_13': '5',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '0',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '0',\n", + " 'l3_n': '14',\n", + " 'l3_1': '9.5',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '10',\n", + " 'l3_8': '10',\n", + " 'l3_9': '0',\n", + " 'l3_10': '0',\n", + " 'l3_11': '10',\n", + " 'l3_12': '5',\n", + " 'l3_13': '10',\n", + " 'l3_14': '10',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '5',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '0',\n", + " 'e1_5': '8',\n", + " 'e1_6': '9',\n", + " 'e1_7': '7',\n", + " 'e1_8': '9',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '10',\n", + " 'e1_14': '0',\n", + " 'e1_15': '0'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '9.5',\n", + " 'l2_4': '9',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9.5',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '10',\n", + " 'l3_6': '10',\n", + " 'l3_7': '9',\n", + " 'l3_8': '10',\n", + " 'l3_9': '3',\n", + " 'l3_10': '0',\n", + " 'l3_11': '3',\n", + " 'l3_12': '3',\n", + " 'l3_13': '5',\n", + " 'l3_14': '2',\n", + " 'l4_n': '11',\n", + " 'l4_1': '0',\n", + " 'l4_2': '0',\n", + " 'l4_3': '0',\n", + " 'l4_4': '0',\n", + " 'l4_5': '0',\n", + " 'l4_6': '0',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '0',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '0',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '5',\n", + " 'e1_5': '5',\n", + " 'e1_6': '0',\n", + " 'e1_7': '0',\n", + " 'e1_8': '10',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '0',\n", + " 'e1_13': '10',\n", + " 'e1_14': '5',\n", + " 'e1_15': '10'},\n", + " {'l1_n': '1',\n", + " 'l1_1': '10',\n", + " 'l2_n': '7',\n", + " 'l2_1': '10',\n", + " 'l2_2': '10',\n", + " 'l2_3': '3',\n", + " 'l2_4': '7',\n", + " 'l2_5': '10',\n", + " 'l2_6': '10',\n", + " 'l2_7': '9',\n", + " 'l3_n': '14',\n", + " 'l3_1': '10',\n", + " 'l3_2': '10',\n", + " 'l3_3': '10',\n", + " 'l3_4': '10',\n", + " 'l3_5': '0',\n", + " 'l3_6': '10',\n", + " 'l3_7': '9',\n", + " 'l3_8': '10',\n", + " 'l3_9': '7',\n", + " 'l3_10': '7',\n", + " 'l3_11': '3',\n", + " 'l3_12': '7',\n", + " 'l3_13': '5',\n", + " 'l3_14': '8',\n", + " 'l4_n': '11',\n", + " 'l4_1': '10',\n", + " 'l4_2': '10',\n", + " 'l4_3': '10',\n", + " 'l4_4': '8',\n", + " 'l4_5': '5',\n", + " 'l4_6': '3',\n", + " 'l4_7': '0',\n", + " 'l4_8': '0',\n", + " 'l4_9': '7',\n", + " 'l4_10': '0',\n", + " 'l4_11': '0',\n", + " 'q1_n': '1',\n", + " 'q1_1': '9.5',\n", + " 'e1_n': '15',\n", + " 'e1_1': '9',\n", + " 'e1_2': '9',\n", + " 'e1_3': '10',\n", + " 'e1_4': '10',\n", + " 'e1_5': '7',\n", + " 'e1_6': '10',\n", + " 'e1_7': '10',\n", + " 'e1_8': '10',\n", + " 'e1_9': '10',\n", + " 'e1_10': '10',\n", + " 'e1_11': '10',\n", + " 'e1_12': '10',\n", + " 'e1_13': '9',\n", + " 'e1_14': '8',\n", + " 'e1_15': '2'}]" + ] + }, + "execution_count": 796, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Your solution here.\n", "\n", "def cvs_reader(filename):\n", " data=list() # if you choose first option\n", + " f=open(filename,\"r\")\n", + " columns = f.readline().rstrip().split(\",\")\n", " \n", - " return data" + " for line in f:\n", + " row = dict()\n", + " l = line.rstrip()\n", + " items = l.split(\",\")\n", + " for i, item in enumerate(items):\n", + " row[columns[i]] = item\n", + " data.append(row)\n", + " f.close()\n", + " return data\n", + "\n", + "cvs_reader(\"Data1401-Grades.csv\")" ] }, { @@ -356,20 +1261,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 797, "metadata": {}, "outputs": [], "source": [ - "import pandas as pd\n", - "class_data=pd.read_csv(\"Data1401-Grades.csv\")\n", + "class_data=cvs_reader(\"Data1401-Grades.csv\")\n", "\n", "a_grade_book=grade_book(\"Data 1401\")\n", "\n", - "for student_i in range(class_data.shape[0]):\n", + "for student_i in range(len(class_data)):\n", " a_student_0=student(\"Student\",str(student_i),student_i)\n", "\n", - " for k in class_data.keys():\n", - " a_student_0.add_grade(grade(k,value=class_data[k][student_i]))\n", + " for k in class_data[student_i].keys():\n", + " a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", "\n", " a_grade_book.add_student(a_student_0)\n", " " @@ -386,7 +1290,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 798, "metadata": {}, "outputs": [], "source": [ @@ -399,38 +1303,117 @@ " def apply(self,a_student):\n", " raise NotImplementedError\n", "\n", - "class grade_summer(summary_calculator):\n", + "class grade_summer(calculator):\n", " def __init__(self,prefix,n):\n", " self.__prefix=prefix\n", " self.__n=n\n", - " summary_calculator.__init__(self,\"Sum Grades\")\n", + " calculator.__init__(self,\"Sum Grades\")\n", " \n", - " def apply(self,a_student):\n", - " labels=[self.__prefix+str(x) for x in range(1,self.__n)]\n", + " def apply(self,a_gradebook,**kwargs):\n", + " labels=[self.__prefix + str(x) for x in range(1,self.__n)]\n", " \n", - " grade_sum=0.\n", - " for label in labels:\n", - " grade_sum+=a_student[label].value()\n", + " for k,a_student in a_grade_book.get_students().items(): \n", + "\n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", "\n", - " a_student.add_grade(grade(self.__prefix+\"sum\",value=grade_sum))" + " a_student.add_grade(grade(self.__prefix+\"sum\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 799, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['e1_', 'l1_', 'l2_', 'l3_', 'l4_', 'q1_']\n" + ] + } + ], + "source": [ + "a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + " for k in class_data[student_i].keys():\n", + " a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", + "\n", + " a_grade_book.add_student(a_student_0)\n", + "#print(class_data)\n", + "prefixes=sorted(list(set([k.split(\"_\")[0] + \"_\" for k in class_data[0].keys()])))\n", + "#labels=[self.__prefix+str(x) for x in range(1,self.__n)]\n", + "print(prefixes)\n", + "for j, prefix in enumerate(prefixes):\n", + " a_grade_book.apply_calculator(grade_summer(prefix, int(list(a_grade_book.get_students().values())[j][prefix+\"n\"].value())+1))" + ] + }, + { + "cell_type": "code", + "execution_count": 800, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_ [35.0, 0, 20.0, 115.0, 24.0, 95.0, 37.0, 77.0, 103.0, 117.0, 138.0, 110.0, 104.0, 111.0, 103.0, 134.0]\n", + "l1_ [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_ [58.0, 0, 0, 62.0, 49.5, 69.0, 54.5, 69.0, 39.5, 60.0, 47.0, 68.5, 64.0, 49.5, 68.0, 59.0]\n", + "l3_ [9.0, 0, 71.0, 102.0, 77.5, 89.0, 64.5, 40.0, 40.0, 26.0, 126.0, 97.5, 115.0, 114.5, 95.0, 106.0]\n", + "l4_ [0, 0, 0, 75.0, 26.0, 35.0, 30.0, 51.0, 68.0, 27.0, 105.0, 51.0, 0, 25.0, 0, 53.0]\n", + "q1_ [9.5, 0, 5.0, 10.0, 0, 9.5, 10.0, 10.0, 9.5, 9.5, 0, 10.0, 10.0, 0, 0, 9.5]\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " print(prefix,list(a_student[prefix+\"sum\"].value() for k,a_student in a_grade_book.get_students().items()))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Curving Grades\n", + "# Curving Grades\n", "\n", "*Exercise 4:* Use the `mean_std_calculator` above to calculate the mean and standard deviation for every lab, quiz, and exam in the class. Add a new print function to the `grade_book` class to print out such information in a nice way, and use this function to show your results.\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 801, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_sum Mean : 82.6875\n", + "e1_sum STD : 42.937045121316864\n", + "l1_sum Mean : 10.0\n", + "l1_sum STD : 0.0\n", + "l2_sum Mean : 51.09375\n", + "l2_sum STD : 21.05663401252679\n", + "l3_sum Mean : 73.3125\n", + "l3_sum STD : 38.301792957379945\n", + "l4_sum Mean : 34.125\n", + "l4_sum STD : 30.421774685248064\n", + "q1_sum Mean : 6.40625\n", + "q1_sum STD : 4.469405546322688\n" + ] + } + ], "source": [ - "# Your solution here" + "# Your solution here\n", + "prefixes=sorted(list(set([k.split(\"_\")[0] + \"_\" for k in class_data[0].keys()])))\n", + "for prefix in prefixes:\n", + " a_grade_book.apply_calculator(mean_std_calculator(grade_name=prefix+\"sum\"))\n", + "a_grade_book.print_data()" ] }, { @@ -442,11 +1425,11 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 802, "metadata": {}, "outputs": [], "source": [ - "class curved_letter_grade(grade_calculator):\n", + "class curved_letter_grade(calculator):\n", " __grades_definition=[ (.97,\"A+\"),\n", " (.93,\"A\"),\n", " (.9,\"A-\"),\n", @@ -470,33 +1453,2302 @@ " self.__mean=mean\n", " self.__std=std\n", " self.__grade_name=grade_name\n", - " grade_calculator.__init__(self,\n", + " calculator.__init__(self,\n", " \"Curved Percent Based Grade Calculator \"+self.__grade_name+ \\\n", " \" Mean=\"+str(self.__mean)+\\\n", " \" STD=\"+str(self.__std)+\\\n", " \" Max=\"+str(self.__max_grade))\n", " \n", "\n", - " def apply(self,a_grade):\n", - " if not isinstance(a_grade,grade):\n", - " print (self.name()+ \" Error: Did not get an proper grade as input.\")\n", - " raise Exception\n", - " if not a_grade.numerical():\n", - " print (self.name()+ \" Error: Did not get a numerical grade as input.\")\n", - " raise Exception\n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if grade_name:\n", + " pass\n", + " else:\n", + " grade_name=self.__grade_name\n", " \n", - " # Rescale the grade\n", - " percent=a_grade.value()/self.__max_grade\n", - " shift_to_zero=percent-(self.__mean/self.__max_grade)\n", - " scale_std=0.1*shift_to_zero/(self.__std/self.__max_grade)\n", - " scaled_percent=scale_std+0.8\n", - " \n", - " for i,v in enumerate(self.__grades_definition):\n", - " if scaled_percent>=v[0]:\n", - " break\n", - " \n", - " return grade(self.__grade_name,value=self.__grades_definition[i][1])\n", - " " + " for k,a_student in a_grade_book.get_students().items():\n", + " a_grade = a_student[grade_name]\n", + "\n", + " if not a_grade.numerical():\n", + " print(self.name()+\"Error: Did not get a numerical grade as input.\")\n", + " raise Exception\n", + "\n", + " # Rescale the grade\n", + " scaled_percent=1\n", + " if self.__std != 0:\n", + " percent=a_grade.value()/self.__max_grade\n", + " shift_to_zero=percent-(self.__mean/self.__max_grade)\n", + " scale_std=0.1*shift_to_zero/(self.__std/self.__max_grade)\n", + " scaled_percent=scale_std+0.8\n", + "\n", + " for i,v in enumerate(self.__grades_definition):\n", + " if scaled_percent>=v[0]:\n", + " break\n", + "\n", + " overwrite = kwargs[\"overwrite\"] if \"overwrite\" in kwargs else False\n", + " #g = grade(grade_name+\" Letter\",value=self.__grades_definition[i][1])\n", + " a_student.add_grade(grade(grade_name+\" Letter\",value=self.__grades_definition[i][1]),overwrite=overwrite)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 803, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F+\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: C\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: F-\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C-\n", + "l3_sum Letter: F-\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F-\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: F-\n", + "q1_sum Letter: F-\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A+\n", + "l1_sum Letter: F-\n", + "l2_sum Letter: F+\n", + "l3_sum Letter: A+\n", + "l4_sum Letter: F\n", + "q1_sum Letter: F-\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " grade_name = prefix+\"sum\"\n", + " a_grade_book.apply_calculator(uncurved_letter_grade_percent(grade_name,max_grade=100))\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": 804, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: C-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: A\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B-\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: A-\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "for prefix in prefixes:\n", + " grade_name = prefix+\"sum\"\n", + " a_grade_book.apply_calculator(curved_letter_grade(grade_name,\n", + " a_grade_book[grade_name+\" Mean\"],\n", + " a_grade_book[grade_name+\" STD\"]),\n", + " overwrite=True)\n", + "a_grade_book.print_students()" ] }, { @@ -510,11 +3762,1300 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 787, "metadata": {}, "outputs": [], "source": [ - "# Your solution here" + "# Your solution here\n", + "class grade_dropper(calculator):\n", + " def __init__(self,prefix,n):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " calculator.__init__(self,\"Final Course Grades\")\n", + " \n", + " def apply(self,a_gradebook,**kwargs):\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " labels=list(filter(lambda x: \n", + " self.__prefix in x, \n", + " a_student.grades().keys()))\n", + " print(labels)\n", + " grade_sum=0.\n", + " grades=list()\n", + " for label in labels:\n", + " if '_' in label and isinstance(a_student[label].value(),(int,float)):\n", + " grades.append(a_student[label].value())\n", + " grades = sorted(grades)\n", + " if len(grades) > self.__n:\n", + " grade_sum = sum(grades[self.__n:])\n", + " else:\n", + " grade_sum = sum(grades)\n", + "# grade_sum = sum(grades)\n", + "\n", + " a_student.add_grade(grade(self.__prefix+\" dropped sum\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 805, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['l1_sum', 'l2_sum', 'l3_sum', 'l4_sum', 'l1_sum Letter', 'l2_sum Letter', 'l3_sum Letter', 'l4_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l1_sum', 'l1_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l2_sum', 'l2_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l3_sum', 'l3_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "['l4_sum', 'l4_sum Letter']\n", + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 8.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 35.0\n", + "l1_sum: 10.0\n", + "l2_sum: 58.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 58.0\n", + "l3_sum dropped sum: 9.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 0\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: C-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 0\n", + "l3_sum dropped sum: 0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 0\n", + "l2_6: 0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 3.0\n", + "l3_8: 6.0\n", + "l3_9: 3.0\n", + "l3_10: 3.0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 5.0\n", + "e1_n: 15.0\n", + "e1_1: 5.0\n", + "e1_2: 5.0\n", + "e1_3: 5.0\n", + "e1_4: 5.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 20.0\n", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "q1_sum: 5.0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: F\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 0\n", + "l3_sum dropped sum: 71.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 5.0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 10.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 10.0\n", + "l4_10: 5.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 7.0\n", + "e1_6: 9.0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 9.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 8.0\n", + "e1_15: 10.0\n", + "e1_sum: 115.0\n", + "l1_sum: 10.0\n", + "l2_sum: 62.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: A\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 62.0\n", + "l3_sum dropped sum: 102.0\n", + "l4_sum dropped sum: 75.0\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 0\n", + "l3_3: 0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 5.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 6.0\n", + "l3_13: 10.0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 6.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 0\n", + "e1_2: 0\n", + "e1_3: 0\n", + "e1_4: 0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 3.0\n", + "e1_10: 3.0\n", + "e1_11: 3.0\n", + "e1_12: 0\n", + "e1_13: 3.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 24.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "q1_sum: 0\n", + "e1_sum Letter: C\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: B-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 49.5\n", + "l3_sum dropped sum: 77.5\n", + "l4_sum dropped sum: 26.0\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.5\n", + "l3_3: 9.5\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 8.0\n", + "l3_10: 0\n", + "l3_11: 5.0\n", + "l3_12: 6.0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 7.0\n", + "e1_8: 0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 95.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B-\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 69.0\n", + "l3_sum dropped sum: 89.0\n", + "l4_sum dropped sum: 35.0\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 5.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 8.0\n", + "l3_5: 10.0\n", + "l3_6: 8.0\n", + "l3_7: 9.0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 10.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 0\n", + "e1_9: 0\n", + "e1_10: 0\n", + "e1_11: 0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 37.0\n", + "l1_sum: 10.0\n", + "l2_sum: 54.5\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B-\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 54.5\n", + "l3_sum dropped sum: 64.5\n", + "l4_sum dropped sum: 30.0\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 10.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 3.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 5.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 7.0\n", + "e1_8: 5.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 77.0\n", + "l1_sum: 10.0\n", + "l2_sum: 69.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: C+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 69.0\n", + "l3_sum dropped sum: 40.0\n", + "l4_sum dropped sum: 51.0\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 3.0\n", + "l4_9: 10.0\n", + "l4_10: 7.0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 10.0\n", + "e1_6: 0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 9.0\n", + "e1_10: 9.0\n", + "e1_11: 9.0\n", + "e1_12: 10.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 39.5\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C\n", + "l3_sum Letter: C-\n", + "l4_sum Letter: A-\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 39.5\n", + "l3_sum dropped sum: 40.0\n", + "l4_sum dropped sum: 68.0\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "e1_sum: 117.0\n", + "l1_sum: 10.0\n", + "l2_sum: 60.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: B+\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: C+\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 60.0\n", + "l3_sum dropped sum: 26.0\n", + "l4_sum dropped sum: 27.0\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 7.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 6.0\n", + "l3_8: 3.0\n", + "l3_9: 10.0\n", + "l3_10: 10.0\n", + "l3_11: 10.0\n", + "l3_12: 10.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 10.0\n", + "l4_6: 5.0\n", + "l4_7: 10.0\n", + "l4_8: 10.0\n", + "l4_9: 10.0\n", + "l4_10: 10.0\n", + "l4_11: 10.0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 9.0\n", + "e1_5: 9.0\n", + "e1_6: 10.0\n", + "e1_7: 9.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 138.0\n", + "l1_sum: 10.0\n", + "l2_sum: 47.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "q1_sum: 0\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A\n", + "l4_sum Letter: A+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 47.0\n", + "l3_sum dropped sum: 126.0\n", + "l4_sum dropped sum: 105.0\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 8.0\n", + "l3_6: 10.0\n", + "l3_7: 8.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 5.0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 10.0\n", + "l4_5: 5.0\n", + "l4_6: 6.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 110.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.5\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 68.5\n", + "l3_sum dropped sum: 97.5\n", + "l4_sum dropped sum: 51.0\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 5.0\n", + "l2_4: 9.5\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 5.0\n", + "l3_2: 9.0\n", + "l3_3: 9.0\n", + "l3_4: 10.0\n", + "l3_5: 7.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 10.0\n", + "l3_10: 7.0\n", + "l3_11: 10.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 10.0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 9.0\n", + "e1_4: 8.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 9.0\n", + "e1_11: 10.0\n", + "e1_12: 9.0\n", + "e1_13: 5.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 104.0\n", + "l1_sum: 10.0\n", + "l2_sum: 64.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "q1_sum: 10.0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: B+\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 64.0\n", + "l3_sum dropped sum: 115.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 0\n", + "l3_n: 14.0\n", + "l3_1: 9.5\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 10.0\n", + "l3_8: 10.0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 10.0\n", + "l3_12: 5.0\n", + "l3_13: 10.0\n", + "l3_14: 10.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 5.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 0\n", + "e1_5: 8.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 10.0\n", + "e1_14: 0\n", + "e1_15: 0\n", + "e1_sum: 111.0\n", + "l1_sum: 10.0\n", + "l2_sum: 49.5\n", + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: C+\n", + "l3_sum Letter: A-\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 49.5\n", + "l3_sum dropped sum: 114.5\n", + "l4_sum dropped sum: 25.0\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 9.5\n", + "l2_4: 9.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.5\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 10.0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 3.0\n", + "l3_10: 0\n", + "l3_11: 3.0\n", + "l3_12: 3.0\n", + "l3_13: 5.0\n", + "l3_14: 2.0\n", + "l4_n: 11.0\n", + "l4_1: 0\n", + "l4_2: 0\n", + "l4_3: 0\n", + "l4_4: 0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 0\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 5.0\n", + "e1_5: 5.0\n", + "e1_6: 0\n", + "e1_7: 0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 10.0\n", + "e1_sum: 103.0\n", + "l1_sum: 10.0\n", + "l2_sum: 68.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum Letter: B\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B+\n", + "l3_sum Letter: B\n", + "l4_sum Letter: C+\n", + "q1_sum Letter: C\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 68.0\n", + "l3_sum dropped sum: 95.0\n", + "l4_sum dropped sum: 0\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "l2_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 3.0\n", + "l2_4: 7.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 9.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 10.0\n", + "l3_3: 10.0\n", + "l3_4: 10.0\n", + "l3_5: 0\n", + "l3_6: 10.0\n", + "l3_7: 9.0\n", + "l3_8: 10.0\n", + "l3_9: 7.0\n", + "l3_10: 7.0\n", + "l3_11: 3.0\n", + "l3_12: 7.0\n", + "l3_13: 5.0\n", + "l3_14: 8.0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 10.0\n", + "l4_4: 8.0\n", + "l4_5: 5.0\n", + "l4_6: 3.0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 7.0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 10.0\n", + "e1_5: 7.0\n", + "e1_6: 10.0\n", + "e1_7: 10.0\n", + "e1_8: 10.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 10.0\n", + "e1_13: 9.0\n", + "e1_14: 8.0\n", + "e1_15: 2.0\n", + "e1_sum: 134.0\n", + "l1_sum: 10.0\n", + "l2_sum: 59.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "q1_sum: 9.5\n", + "e1_sum Letter: A-\n", + "l1_sum Letter: A+\n", + "l2_sum Letter: B\n", + "l3_sum Letter: B+\n", + "l4_sum Letter: B\n", + "q1_sum Letter: B\n", + "l1_sum dropped sum: 10.0\n", + "l2_sum dropped sum: 59.0\n", + "l3_sum dropped sum: 106.0\n", + "l4_sum dropped sum: 53.0\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "# a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "# for student_i in range(len(class_data)):\n", + "# a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + "# for k in class_data[student_i].keys():\n", + "# a_student_0.add_grade(grade(k,value=float(class_data[student_i][k])))\n", + "\n", + "# a_grade_book.add_student(a_student_0)\n", + "lab_prefixes = list(filter(lambda x: 'l' in x and 'sum' in x, list(a_grade_book.get_students().values())[0].grades().keys()))\n", + "print(lab_prefixes)\n", + "\n", + "for prefix in lab_prefixes:\n", + " if ' ' not in prefix:\n", + " a_grade_book.apply_calculator(grade_dropper(prefix,1), overwrite=True)\n", + "a_grade_book.print_students()" ] }, { @@ -578,7 +5119,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.8.0" + "version": "3.7.2" } }, "nbformat": 4,