diff --git a/Exams/Final/Final-solution-NabinBasnet.ipynb b/Exams/Final/Final-solution-NabinBasnet.ipynb new file mode 100644 index 0000000..b21fa1d --- /dev/null +++ b/Exams/Final/Final-solution-NabinBasnet.ipynb @@ -0,0 +1,1054 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Final Exam\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/Exams/Final/Final.ipynb)" + ] + }, + { + "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 = (y2-y1) / (x2-x1)\n", + " for x in range(x1,x2):\n", + " y= int(slope * x)+x\n", + " self.set_pixel(x,y, **kargs)\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", + " #Added for Q.4, note it is overloading in every shape class below\n", + " def __str__(self): pass\n", + " \n", + " \n", + "class Rectangle(Shape):\n", + " def __init__(self,x, y, w, h,name=\"\", **kwargs):\n", + " super().__init__(name=\"\", **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.w = w\n", + " self.h = h\n", + " self.name=\"Rectangle\"\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", + " return f'{self.name}({self.x},{self.y},{self.w},{self.h})'\n", + "\n", + "class Square(Rectangle):\n", + " def __init__(self, x, y, size,name=\"\", **kwargs):\n", + " super().__init__(x, y, size, size,name=\"\", **kwargs)\n", + " self.name=\"Square\"\n", + " \n", + " def __str__(self):\n", + " return f'{self.name}({self.x},{self.y},{self.w})'\n", + " \n", + "class Line(Shape):\n", + " def __init__(self, x1, y1, x2, y2,name=\"\", **kwargs):\n", + " super().__init__(name=\"\",**kwargs)\n", + " self.x1=x1\n", + " self.y1=y1\n", + " self.x2=x2\n", + " self.y2=y2\n", + " self.name=\"Line\"\n", + " def paint(self, canvas):\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2)\n", + " def __str__(self):\n", + " return f'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": [ + "C=Canvas(20,20)\n", + "rec=Rectangle(10,10,20,20,char=\"^\")\n", + "square=Square(10,10,20)\n", + "line=Line(0,0,5,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "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+\"_\"+name+\"_\"+str(i)\n", + " \n", + " return name\n", + " \n", + " #Added Save and Load class below for Q5\n", + " def save(self,file_name):\n", + " self.file_name = file_name\n", + " file = open(self.file_name,'a')\n", + " for key in self.shapes.keys():\n", + " file.write(key)\n", + " file.write(\"\\n\")\n", + " file.close()\n", + " \n", + " def load(self,file_name):\n", + " self.file_name = file_name\n", + " file=open(self.file_name,\"r\")\n", + " C=Canvas(50,50)\n", + " raster = RasterDrawing()\n", + " for shape in file:\n", + " raster.add_shape(eval(shape))\n", + " raster.paint(C)\n", + " C.display()\n", + "\n", + " file.close()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "1. Add `Point` and `Triangle` classes and test them." + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "class Point(Shape):\n", + " def __init__(self, x, y,name=\"\",**kwargs):\n", + " Shape.__init__(self, name=\"\",**kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.name=\"Point\"\n", + " \n", + " def paint(self, canvas):\n", + " canvas.set_pixel(self.x, self.y, **self.kwargs) \n", + " \n", + " def __str__(self):\n", + " return f'{self.name}({self.x},{self.y})' \n", + " \n", + "class Traingle(Shape):\n", + " def __init__(self, x1, y1, x2, y2, x3,y3,name=\"\", **kwargs):\n", + " Shape.__init__(self,name=\"\", **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", + " self.name=\"Traingle\"\n", + " \n", + " def paint(self, canvas):\n", + " if self.y1==self.y2:\n", + " h1=abs(self.x1-self.x2)\n", + " canvas.h_line(self.x1,self.y1,h1,**self.kwargs)\n", + " if self.x1==self.x2:\n", + " w1=(self.y1-self.y2)\n", + " canvas.v_line(self.x1,self.y1,w1,**self.kwargs)\n", + " if self.y1!=self.y2 and self.x1!=self.x2:\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2,**self.kwargs)\n", + " \n", + " if self.y1==self.y3:\n", + " h2=abs(self.x1-self.x3)\n", + " canvas.h_line(self.x1,self.y1,h2,**self.kwargs)\n", + " if self.x1==self.x3:\n", + " w2=abs(self.y1-self.y3)\n", + " canvas.v_line(self.x1,self.y1,w2,**self.kwargs)\n", + " if self.y1!=self.y3 and self.x1!=self.x3:\n", + " canvas.line(self.x1,self.y1,self.x3,self.y3,**self.kwargs) \n", + " if self.y2==self.y3:\n", + " h3=(self.x3-self.x2)\n", + " canvas.h_line(self.x2,self.y2,h3,**self.kwargs)\n", + " if self.x2==self.x3:\n", + " w3=(self.y3-self.y2)\n", + " canvas.v_line(self.x2,self.y2,w3,**self.kwargs)\n", + " if self.y2!=self.y3 and self.x2!=self.x3: \n", + " canvas.line(self.x2,self.y2,self.x3,self.y3,**self.kwargs)\n", + "\n", + " \n", + " def __str__(self):\n", + " return f'{self.name}({self.x1},{self.y1},{self.x2},{self.y2},{self.x3},{self.y3})' " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "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" + ] + } + ], + "source": [ + "D=Canvas(20,20)\n", + "point=Point(5,5)\n", + "point.paint(D)\n", + "traingle=Traingle(0,0,10,0,10,10)\n", + "traingle.paint(D)\n", + "D.display()\n", + "#Note that the x and y pixels are not same so it doesn't like the bottom corner is joined." + ] + }, + { + "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": 7, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "class Arc(Shape):\n", + " def __init__(self, h, k, a, b, s_a,e_a,name=\"\", **kwargs):\n", + " Shape.__init__(self,name=\"\", **kwargs)\n", + " self.h=h # x for center\n", + " self.k=k # y for center\n", + " self.a=a # width from center(h) in x direction\n", + " self.b=b # width from center(k) in y direction\n", + " self.s_a=s_a # starting angle\n", + " self.e_a=e_a # ending angle\n", + " self.name=\"Arc\"\n", + " \n", + " def paint(self, canvas): \n", + " \n", + " if (self.s_a + self.e_a)<360:\n", + " \n", + " for angle in range(self.s_a,self.e_a+1):\n", + " y=int((self.k+self.b)*math.cos(angle*0.0175))\n", + " c=(1-((y-self.k)/self.b)**2)\n", + " if c>0:\n", + " x = int(self.h+self.a*(math.sqrt(c)))\n", + " canvas.set_pixel(x,y)\n", + " else: pass\n", + " else: \n", + " for y in range(self.k-self.b,self.k+self.b+1):\n", + " x = int(self.h+self.a*(math.sqrt(1-((y-self.k)/self.b)**2)))\n", + " canvas.set_pixel(x,y)\n", + " x1 = -x\n", + " canvas.set_pixel(x1,y)\n", + " \n", + " def __str__(self):\n", + " return f'{self.name}({self.h},{self.k},{self.a},{self.b},{self.s_a},{self.e_a})' \n", + "\n", + "class Oval(Arc):\n", + " def __init__(self, h, k, a, b, s_a,e_a,name=\"\", **kwargs):\n", + " super().__init__(h, k, a, b,s_a,e_a,name=\"\", **kwargs)\n", + " self.name=\"Oval\"\n", + " \n", + " def __str__(self):\n", + " return f'{self.name}({self.h},{self.k},{self.a},{self.b},{self.s_a},{self.e_a})' \n", + "\n", + "class Circle(Arc):\n", + " def __init__(self, h, k, r, s_a,e_a,name=\"\", **kwargs):\n", + " super().__init__(h, k, r, r,s_a,e_a,name=\"\", **kwargs)\n", + " self.name=\"Circle\"\n", + " def __str__(self):\n", + " return f'{self.name}({self.h},{self.k},{self.a},{self.s_a},{self.e_a})' \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "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", + " * \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "#Test for Arc\n", + "C2=Canvas(30,30)\n", + "arc=Arc(15,15,10,10,0,270)\n", + "arc.paint(C2)\n", + "C2.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "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", + " * \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "#Test for Oval\n", + "C3=Canvas(30,30)\n", + "oval=Oval(15,15,10,5,0,360)\n", + "oval.paint(C3)\n", + "C3.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "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", + " * \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "#Test for Circle\n", + "C4=Canvas(30,30)\n", + "circle=Circle(15,15,10,0,360)\n", + "circle.paint(C4)\n", + "C4.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "3. Use your classes to create a `RasterDrawing` that draws a happy face." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "#Using Raster Function\n", + "C55=Canvas(50,50)\n", + "raster=RasterDrawing()" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Circle(25,25,20,0,360))\n", + "raster.paint(C55)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Square(15,12,4))\n", + "raster.paint(C55)" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Square(15,35,4))\n", + "raster.paint(C55)" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Arc(30,25,6,5,0,180))\n", + "raster.paint(C55)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Circle(25,25,2,0,360))\n", + "raster.paint(C55)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "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", + " * * * * \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": [ + "raster.paint(C55)\n", + "C55.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "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", + " * * * * \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": [ + "#Using Compound function\n", + "C5=Canvas(50,50)\n", + "coumpound=CompoundShape([Circle(25,25,20,0,360),Circle(25,25,2,0,360),Square(15,12,4),Square(15,35,4),Arc(30,25,6,5,0,180)])\n", + "coumpound.paint(C5)\n", + "C5.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": 19, + "metadata": {}, + "outputs": [], + "source": [ + "#Note that the __str__() class is added in each shape class above\n", + "rec=Rectangle(10,10,20,20)\n", + "sqr=Square(10,10,20)\n", + "lin=Line(0,0,5,5)\n", + "pnt=Point(5,5)\n", + "trg=Traingle(0,0,10,0,10,10)\n", + "arc=Arc(25,25,20,20,0,85)\n", + "ovl=Oval(25,25,20,15,0,360)\n", + "crc=Circle(25,25,15,0,360)" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Rectangle(10,10,20,20)'" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rec.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Square(10,10,20)'" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sqr.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Line(0,0,5,5)'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lin.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Point(5,5)'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "pnt.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Traingle(0,0,10,0,10,10)'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "trg.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Arc(25,25,20,20,0,85)'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "arc.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Oval(25,25,20,15,0,360)'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ovl.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Circle(25,25,15,0,360)'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "crc.__str__()" + ] + }, + { + "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": 28, + "metadata": {}, + "outputs": [], + "source": [ + "raster = RasterDrawing()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "raster.add_shape(Shape(\"Circle(25,25,20,0,360)\"))\n", + "raster.add_shape(Shape(\"Square(15,12,4)\"))\n", + "raster.add_shape(Shape(\"Square(15,35,4)\"))\n", + "raster.add_shape(Shape(\"Arc(30,25,6,5,0,180)\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "dict_keys(['Circle(25,25,20,0,360)', 'Square(15,12,4)', 'Square(15,35,4)', 'Arc(30,25,6,5,0,180)'])" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "raster.shapes.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "raster.save(\"Shapes12.txt\")" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "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", + " * * \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": [ + "RasterDrawing().load(\"Shapes12.txt\")" + ] + }, + { + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Exams/Mid-term/Exam-solution-Basnet.ipynb b/Exams/Mid-term/Exam-solution-Basnet.ipynb new file mode 100644 index 0000000..9726ffb --- /dev/null +++ b/Exams/Mid-term/Exam-solution-Basnet.ipynb @@ -0,0 +1,450 @@ +{ + "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": 338, + "metadata": {}, + "outputs": [], + "source": [ + "def first_alphabetically(lst):\n", + " out_word=lst[0]\n", + " for i, word in enumerate(lst):\n", + " if lst[i]=bin_edges[i] and d\" 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":{"colab_type":"text","id":"H5vxtcXnqvz6"},"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":{"colab_type":"code","id":"twRKNaGy3XGw","colab":{"base_uri":"https://localhost:8080/","height":116},"outputId":"b70921de-9143-49a4-d579-315ec8fcde4e"},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (118): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# "],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"DZODNKiAqvz8"},"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":{"colab_type":"code","id":"oP9XlZl_3iZD","colab":{}},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"v5IaZXNyqvz_"},"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":{"colab_type":"text","id":"J_R64sQDqv0A"},"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":{"colab_type":"text","id":"edTvE6rOqv0C"},"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":{"colab_type":"code","id":"e5tXg0f8qv0D","colab":{}},"source":["%cd /content/drive/My\\ Drive\n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"WYsyYcg1qv0J"},"source":["Make a new directory:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"Z7noY1hMqv0L","colab":{}},"source":["!mkdir Data-1401-Repo\n","%cd Data-1401-Repo"],"execution_count":0,"outputs":[]},{"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//DATA1401-Spring-2020.git"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"cOAuqTVUqv0V"},"source":["Go into the directory:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"b1Ew4tEZqv0X","colab":{}},"source":["%cd DATA1401-Spring-2020\n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"IrhWToc-qv0a"},"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":{"colab_type":"code","id":"JxtMYR-9qv0c","colab":{}},"source":["!git remote -v"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"9ud3X0fBqv0f"},"source":["Now use the original class URL to set your upstream:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"pgJlKxBqqv0h","colab":{}},"source":["!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"colab_type":"code","id":"id2yUEt9qv0k","colab":{}},"source":["!git remote -v"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"sAkgeJ6Iqv0n"},"source":["From now on, you can get the newest version of class material by using:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"AGDsfTFLqv0o","colab":{}},"source":["!git pull"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"u9RAhs5b4vXY"},"source":["We will submit your Lab 1 using git at the next Lab."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"PPfGmFQI40HR","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]} \ No newline at end of file diff --git a/Labs/Lab-1/Lab-1-solution.ipynb b/Labs/Lab-1/Lab-1-solution.ipynb new file mode 100644 index 0000000..849bad4 --- /dev/null +++ b/Labs/Lab-1/Lab-1-solution.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Copy of Lab-1.ipynb","provenance":[{"file_id":"https://github.com/afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-1/Lab-1.ipynb","timestamp":1581107898898}],"collapsed_sections":[]},"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"}},"cells":[{"cell_type":"markdown","metadata":{"colab_type":"text","id":"O5vg8KKRq0sy"},"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":"markdown","metadata":{"colab_type":"text","id":"FVt_1hPt1dAK"},"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":{"colab_type":"text","id":"x0JBL_RFrDDj"},"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":{"colab_type":"text","id":"hwJ6wJk3tiLv"},"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":{"colab_type":"text","id":"TjfIzdQZqvzk"},"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":{"colab_type":"text","id":"C_LmOgzFqvzp"},"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":{"colab_type":"code","id":"KJ5f-WO0wcAv","colab":{}},"source":["!ls\n","!echo \"----------\"\n","!ls sample_data"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"8f-n4AXFw-dD"},"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":{"colab_type":"code","id":"99nrBYTWxZJr","colab":{}},"source":["!echo \"Technique 1:\"\n","!ls\n","!cd sample_data\n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"colab_type":"code","id":"2-Znf97Lxl-Z","colab":{}},"source":["!echo \"Technique 2:\"\n","!ls ; cd sample_data ;ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"4x9n1rAkxyYl"},"source":["Notebooks allow a bit of \"magic\" (using \"%\") to avoid some of these limitations:\n"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"vLBPTX4rx3gd","colab":{}},"source":["!echo \"Technique 3:\"\n","!ls \n","%cd sample_data \n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"U8XpvPjcyH0w"},"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":{"colab_type":"code","id":"MIDFitLZyuZy","colab":{}},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"q-4hfZBywW25"},"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":{"colab_type":"text","id":"51Eya4LBqvzs"},"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":"code","metadata":{"id":"A3XhHBRPUe4H","colab_type":"code","outputId":"981db836-54ad-4c36-a85a-927adb5d5192","executionInfo":{"status":"ok","timestamp":1581107008370,"user_tz":360,"elapsed":2429,"user":{"displayName":"","photoUrl":"","userId":""}},"colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["!echo $shell"],"execution_count":0,"outputs":[{"output_type":"stream","text":["\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"YS7YFiPwqvzu"},"source":["!/bin/bash --noediting"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"YoEgruUhqvzw"},"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":"nEeHYkrUXIch","colab_type":"code","outputId":"46fbdee5-7d01-4f87-832b-f2ff76fa94e4","colab":{"base_uri":"https://localhost:8080/","height":191},"executionInfo":{"status":"ok","timestamp":1581108392829,"user_tz":360,"elapsed":138750,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["!/bin/bash --noediting"],"execution_count":3,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (118): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive/\"my drive\"\n","bash: cd: drive/my drive: No such file or directory\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n","\u001b]0;root@2704468153c2: /content/drive\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd \"My Drive\"\n","\u001b]0;root@2704468153c2: /content/drive/My Drive\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1441\n","\u001b]0;root@2704468153c2: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# mkdir lab-1-Solution\n","\u001b]0;root@2704468153c2: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"M8prboieZFg7","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":124},"outputId":"7f906728-d6e7-4ef3-b9e9-c87d9f6f6b73","executionInfo":{"status":"ok","timestamp":1581108239224,"user_tz":360,"elapsed":36253,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":2,"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":"code","metadata":{"colab_type":"code","id":"A16VzZ3G0J8x","outputId":"3388faef-187a-4a6b-a94d-8997d7199dec","executionInfo":{"status":"ok","timestamp":1581107454842,"user_tz":360,"elapsed":119933,"user":{"displayName":"","photoUrl":"","userId":""}},"colab":{"base_uri":"https://localhost:8080/","height":191}},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (124): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# pwd\n","/content\n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# cd.. \n","bash: cd..: command not found\n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@9f027f44ce11: /content\u0007\u001b[01;32mroot@9f027f44ce11\u001b[00m:\u001b[01;34m/content\u001b[00m# ^C\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"o38c4lbsqvzy"},"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":{"colab_type":"code","id":"yNj2LXzP2ksl","colab":{"base_uri":"https://localhost:8080/","height":399},"outputId":"dde32dae-2a0d-4fb6-fb0b-1d4c6a641055","executionInfo":{"status":"ok","timestamp":1581108619379,"user_tz":360,"elapsed":174521,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["!/bin/bash --noediting"],"execution_count":4,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (118): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\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@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# there is 1 storage device (sda) and they have 12 partition\n","bash: syntax error near unexpected token `('\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"7P9EG0KOqvz2"},"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":{"colab_type":"code","id":"UlsANMuf2qMs","colab":{"base_uri":"https://localhost:8080/","height":1000},"outputId":"5f9c20fd-9bac-489d-eab6-d88999f6e1a0","executionInfo":{"status":"ok","timestamp":1581109002029,"user_tz":360,"elapsed":330828,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["!/bin/bash --noediting"],"execution_count":5,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (118): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# ls\n","\u001b[0m\u001b[01;34mdrive\u001b[0m \u001b[01;34msample_data\u001b[0m\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /etc/passwd\n","/etc/passwd\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /etc\n","adduser.conf \u001b[0m\u001b[01;34mgtk-3.0\u001b[0m mke2fs.conf \u001b[01;34mrc4.d\u001b[0m\n","\u001b[01;34malternatives\u001b[0m host.conf \u001b[01;34mmodprobe.d\u001b[0m \u001b[01;34mrc5.d\u001b[0m\n","\u001b[01;34mapparmor.d\u001b[0m hostname modules \u001b[01;34mrc6.d\u001b[0m\n","\u001b[01;34mapt\u001b[0m hosts \u001b[01;34mmodules-load.d\u001b[0m \u001b[01;34mrcS.d\u001b[0m\n","bash.bashrc hosts.allow \u001b[01;36mmtab\u001b[0m resolv.conf\n","\u001b[01;34mbash_completion.d\u001b[0m hosts.deny \u001b[01;34mmysql\u001b[0m \u001b[01;32mrmt\u001b[0m\n","bindresvport.blacklist \u001b[01;34minit.d\u001b[0m networks securetty\n","\u001b[01;34mbinfmt.d\u001b[0m inputrc nsswitch.conf \u001b[01;34msecurity\u001b[0m\n","\u001b[01;34mca-certificates\u001b[0m \u001b[01;34mipython\u001b[0m \u001b[01;34mODBCDataSources\u001b[0m \u001b[01;34mselinux\u001b[0m\n","ca-certificates.conf issue odbc.ini sensors3.conf\n","\u001b[01;34mcalendar\u001b[0m issue.net odbcinst.ini \u001b[01;34msensors.d\u001b[0m\n","\u001b[01;34mcron.daily\u001b[0m \u001b[01;34mjava-11-openjdk\u001b[0m \u001b[01;34mopenal\u001b[0m shadow\n","\u001b[01;34mcron.weekly\u001b[0m \u001b[01;34mjava-8-openjdk\u001b[0m \u001b[01;34mOpenCL\u001b[0m shadow-\n","\u001b[01;34mdbus-1\u001b[0m \u001b[01;34mjupyter\u001b[0m \u001b[01;34mopenmpi\u001b[0m shells\n","debconf.conf \u001b[01;34mkernel\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34mskel\u001b[0m\n","debian_version \u001b[01;34mldap\u001b[0m \u001b[01;36mos-release\u001b[0m \u001b[01;34mssh\u001b[0m\n","\u001b[01;34mdefault\u001b[0m ld.so.cache pam.conf \u001b[01;34mssl\u001b[0m\n","deluser.conf ld.so.conf \u001b[01;34mpam.d\u001b[0m subgid\n","\u001b[01;34mdepmod.d\u001b[0m \u001b[01;34mld.so.conf.d\u001b[0m papersize subuid\n","\u001b[01;34mdhcp\u001b[0m legal passwd sudoers\n","\u001b[01;34mdkms\u001b[0m libaudit.conf passwd- \u001b[01;34msudoers.d\u001b[0m\n","\u001b[01;34mdpkg\u001b[0m \u001b[01;34mlibibverbs.d\u001b[0m \u001b[01;34mperl\u001b[0m sysctl.conf\n","\u001b[01;34memacs\u001b[0m \u001b[01;34mlibnl-3\u001b[0m \u001b[01;32mpip.conf\u001b[0m \u001b[01;34msysctl.d\u001b[0m\n","environment \u001b[01;34mlibpaper.d\u001b[0m \u001b[01;34mpolkit-1\u001b[0m \u001b[01;34msystemd\u001b[0m\n","ffserver.conf locale.alias profile \u001b[01;34mterminfo\u001b[0m\n","\u001b[01;34mfonts\u001b[0m locale.gen \u001b[01;34mprofile.d\u001b[0m timezone\n","fstab \u001b[01;36mlocaltime\u001b[0m \u001b[01;34mpulse\u001b[0m \u001b[01;34mtmpfiles.d\u001b[0m\n","fuse.conf \u001b[01;34mlogcheck\u001b[0m \u001b[01;34mpython\u001b[0m ucf.conf\n","gai.conf login.defs \u001b[01;34mpython2.7\u001b[0m \u001b[01;34mudev\u001b[0m\n","\u001b[01;34mglvnd\u001b[0m \u001b[01;34mlogrotate.d\u001b[0m \u001b[01;34mpython3\u001b[0m \u001b[01;34mupdate-motd.d\u001b[0m\n","\u001b[01;34mgroff\u001b[0m lsb-release \u001b[01;34mpython3.6\u001b[0m vdpau_wrapper.cfg\n","group machine-id \u001b[01;34mR\u001b[0m wgetrc\n","group- mailcap \u001b[01;34mrc0.d\u001b[0m \u001b[01;34mX11\u001b[0m\n","gshadow mailcap.order \u001b[01;34mrc1.d\u001b[0m \u001b[01;34mxdg\u001b[0m\n","gshadow- manpath.config \u001b[01;34mrc2.d\u001b[0m\n","\u001b[01;34mgss\u001b[0m mime.types \u001b[01;34mrc3.d\u001b[0m\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# cat /etc/passwd\n","root:x:0:0:root:/root:/bin/bash\n","daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n","bin:x:2:2:bin:/bin:/usr/sbin/nologin\n","sys:x:3:3:sys:/dev:/usr/sbin/nologin\n","sync:x:4:65534:sync:/bin:/bin/sync\n","games:x:5:60:games:/usr/games:/usr/sbin/nologin\n","man:x:6:12:man:/var/cache/man:/usr/sbin/nologin\n","lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin\n","mail:x:8:8:mail:/var/mail:/usr/sbin/nologin\n","news:x:9:9:news:/var/spool/news:/usr/sbin/nologin\n","uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin\n","proxy:x:13:13:proxy:/bin:/usr/sbin/nologin\n","www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin\n","backup:x:34:34:backup:/var/backups:/usr/sbin/nologin\n","list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin\n","irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin\n","gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin\n","nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin\n","_apt:x:100:65534::/nonexistent:/usr/sbin/nologin\n","systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin\n","systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin\n","messagebus:x:103:107::/nonexistent:/usr/sbin/nologin\n","nvidia-persistenced:x:104:108:NVIDIA Persistence Daemon,,,:/nonexistent:/sbin/nologin\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -i -c W /etc/passwd\n","3\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"SZuhLbD8qvz5"},"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":{"colab_type":"text","id":"H5vxtcXnqvz6"},"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":{"colab_type":"code","id":"twRKNaGy3XGw","colab":{"base_uri":"https://localhost:8080/","height":116},"outputId":"b70921de-9143-49a4-d579-315ec8fcde4e"},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (118): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@2704468153c2: /content\u0007\u001b[01;32mroot@2704468153c2\u001b[00m:\u001b[01;34m/content\u001b[00m# "],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"DZODNKiAqvz8"},"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":{"colab_type":"code","id":"oP9XlZl_3iZD","colab":{}},"source":["!/bin/bash --noediting"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"v5IaZXNyqvz_"},"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":{"colab_type":"text","id":"J_R64sQDqv0A"},"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":{"colab_type":"text","id":"edTvE6rOqv0C"},"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":{"colab_type":"code","id":"e5tXg0f8qv0D","colab":{}},"source":["%cd /content/drive/My\\ Drive\n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"WYsyYcg1qv0J"},"source":["Make a new directory:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"Z7noY1hMqv0L","colab":{}},"source":["!mkdir Data-1401-Repo\n","%cd Data-1401-Repo"],"execution_count":0,"outputs":[]},{"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//DATA1401-Spring-2020.git"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"cOAuqTVUqv0V"},"source":["Go into the directory:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"b1Ew4tEZqv0X","colab":{}},"source":["%cd DATA1401-Spring-2020\n","!ls"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"IrhWToc-qv0a"},"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":{"colab_type":"code","id":"JxtMYR-9qv0c","colab":{}},"source":["!git remote -v"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"9ud3X0fBqv0f"},"source":["Now use the original class URL to set your upstream:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"pgJlKxBqqv0h","colab":{}},"source":["!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"colab_type":"code","id":"id2yUEt9qv0k","colab":{}},"source":["!git remote -v"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"sAkgeJ6Iqv0n"},"source":["From now on, you can get the newest version of class material by using:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"AGDsfTFLqv0o","colab":{}},"source":["!git pull"],"execution_count":0,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"u9RAhs5b4vXY"},"source":["We will submit your Lab 1 using git at the next Lab."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"PPfGmFQI40HR","colab":{}},"source":[""],"execution_count":0,"outputs":[]}]} \ No newline at end of file diff --git a/Labs/Lab-2/Lab-2-solution2.ipynb b/Labs/Lab-2/Lab-2-solution2.ipynb new file mode 100644 index 0000000..ec6d850 --- /dev/null +++ b/Labs/Lab-2/Lab-2-solution2.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3"},"colab":{"name":"Lab-2-solution2.ipynb","provenance":[{"file_id":"1sFikZUksBGx_RZSycUUmwO0FhzroJrhM","timestamp":1581310629188},{"file_id":"https://github.com/afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-2/Lab-2.ipynb","timestamp":1581179416634}],"collapsed_sections":[]}},"cells":[{"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":["def even(x):\n"," return x %2 ==0\n","def odd(x):\n"," return x %2 !=0"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"xNJAcodhdBHB","colab_type":"code","outputId":"8bcd9395-cca5-44fa-ff44-729bc54d37c2","executionInfo":{"status":"ok","timestamp":1581308925134,"user_tz":360,"elapsed":472,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}},"colab":{"base_uri":"https://localhost:8080/","height":87}},"source":["print (\"Testing even 2:\", even(2))\n","print (\"Testing even 3:\", even(3))\n","print (\"Testing odd 4:\", odd(4))\n","print (\"Testing odd 5:\", odd(5))"],"execution_count":0,"outputs":[{"output_type":"stream","text":["Testing even 2: True\n","Testing even 3: False\n","Testing odd 4: False\n","Testing odd 5: 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":["def less_than_ten(lst):\n"," out_list = list()\n"," for element in lst:\n"," if element <10:\n"," out_list.append(element)\n"," return out_list"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"__HTUWA1dBHH","colab_type":"code","outputId":"8b0d05fc-9ab0-4801-aeeb-01458d293b80","executionInfo":{"status":"ok","timestamp":1581395085776,"user_tz":360,"elapsed":605,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}},"colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["print(less_than_ten([2,8,10,12,100,-50]))"],"execution_count":0,"outputs":[{"output_type":"stream","text":["[2, 8, -50]\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":["def less_than_max(lst):\n"," x_max = max(lst)\n"," out_list = list()\n"," for element in lst:\n"," if element 1 only\")\n"," elif n==1:\n"," fibonnaci_sequence.append(i)\n"," elif n>=2:\n"," fibonnaci_sequence.append(i)\n"," fibonnaci_sequence.append(j)\n","\n"," for r in range(2,n):\n"," r = i+j\n"," i=j\n"," j=r\n"," fibonnaci_sequence.append(r)\n"," return fibonnaci_sequence\n"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"rzK5FskJdBHj","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":35},"outputId":"93353d87-6b93-4b78-8c26-116139ef7ca9","executionInfo":{"status":"ok","timestamp":1581653078699,"user_tz":360,"elapsed":391,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["#fibonnaci(0)\n","fibonnaci(10)"],"execution_count":17,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]"]},"metadata":{"tags":[]},"execution_count":17}]},{"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":["def word_game(word):\n"," reverse_word = list()\n"," word.reverse()\n"," reverse_word.append(word)\n"," return reverse_word\n"],"execution_count":0,"outputs":[]},{"cell_type":"code","metadata":{"id":"nQyhnLZ_dBHn","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":35},"outputId":"f407b65b-5664-4542-e25d-eab0f7c449e8","executionInfo":{"status":"ok","timestamp":1581653679512,"user_tz":360,"elapsed":419,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["word_game([\"university\" ,\"texas\", \"arlington\"])"],"execution_count":30,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[['arlington', 'texas', 'university']]"]},"metadata":{"tags":[]},"execution_count":30}]},{"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":{"base_uri":"https://localhost:8080/","height":295},"outputId":"a5515f3c-f901-4488-c4ec-272e842e3188","executionInfo":{"status":"ok","timestamp":1581655955382,"user_tz":360,"elapsed":18180,"user":{"displayName":"Nabin Basnet","photoUrl":"https://lh3.googleusercontent.com/a-/AAuE7mD_O4cP71trbaB-9Dmz3RYH1d5GpGJsmmVbkJwj=s64","userId":"09849094283825066695"}}},"source":["import random\n","number_of_try = 0\n","number = random.randint(1,10)\n","\n","while number_of_try<5:\n"," print(\"Guess a number between 1 and 10\") \n"," guess = input()\n"," guess = int(guess)\n"," number_of_try = number_of_try + 1\n","\n"," if guess < number:\n"," print (\"Your Guess is too Low\")\n","\n"," if guess > number:\n"," print (\"Your Guess is too High\")\n","\n"," if guess == number:\n"," break\n","if guess == number:\n"," number_of_try = str(number_of_try)\n"," print (\"Great, You Guessed the Correct Number in \" + number_of_try+ \" Try!\")\n","\n","if guess != number:\n"," number = str(number)\n"," print (\"Sorry, Please Try Again, your Guessing number was \" + number)\n","\n"],"execution_count":36,"outputs":[{"output_type":"stream","text":["Guess a number between 1 and 10\n","10\n","Your Guess is too High\n","Guess a number between 1 and 10\n","10\n","Your Guess is too High\n","Guess a number between 1 and 10\n","10\n","Your Guess is too High\n","Guess a number between 1 and 10\n","10\n","Your Guess is too High\n","Guess a number between 1 and 10\n","10\n","Your Guess is too High\n","Sorry, Please Try Again, the number is8\n"],"name":"stdout"}]}]} \ No newline at end of file diff --git a/Labs/Lab-3/Lab_3-Solution-NabinBasnet.ipynb b/Labs/Lab-3/Lab_3-Solution-NabinBasnet.ipynb new file mode 100644 index 0000000..92bf11e --- /dev/null +++ b/Labs/Lab-3/Lab_3-Solution-NabinBasnet.ipynb @@ -0,0 +1,571 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "iOaBNeCUKC36" + }, + "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": { + "colab_type": "text", + "id": "0vzVoO-oKC4D" + }, + "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", + "execution_count": 6, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4PN__jEvKC4G" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the size of n*n matrix Board\n", + "3\n" + ] + }, + { + "data": { + "text/plain": [ + "[[0, 0, 0], [0, 0, 0], [0, 0, 0]]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Write you solution here\n", + "empty = 0\n", + "player_1 = \"X\"\n", + "player_2 = \"O\"\n", + "\n", + "print(\"Enter the size of n*n matrix Board\")\n", + "size = int(input())\n", + "def board(size):\n", + " game_board=[[empty]*size for i in range(size)]\n", + " return game_board\n", + "board(size) " + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "kN1MeCfQKC4S" + }, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0, 0, 0],\n", + " [0, 0, 0, 0, 0],\n", + " [0, 0, 0, 0, 0],\n", + " [0, 0, 0, 0, 0],\n", + " [0, 0, 0, 0, 0]]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "board(5)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "7jmCJMeyKC4b" + }, + "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", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# Write you solution here\n", + "import numpy as np \n", + "\n", + "def horizontals (board):\n", + " for row in board:\n", + " if len(set(row))==1:\n", + " return row[0]\n", + " return False\n", + " \n", + "def verticals(board):\n", + " tboard=zip(*board)\n", + " for row in tboard:\n", + " if len(set(row))==1:\n", + " return row[0] if row[0] is not 0 else False\n", + " return False \n", + " \n", + "def diagonals(board):\n", + " x=len(board)\n", + " d = []\n", + " for i in range(x):\n", + " d.append(board[i][i])\n", + " if len(set(d)) == 1:\n", + " return d[0]\n", + " for i in range(x):\n", + " d.append(board[i][x-i-1])\n", + " if len(set(d)) == 1:\n", + " return d[0]\n", + " return False\n", + "\n", + "\n", + "def winner(board):\n", + " result = horizontals(board)\n", + " if result:\n", + " return result\n", + " result = verticals(board)\n", + " if result:\n", + " return result\n", + " result = diagonals(board)\n", + " if result:\n", + " return result\n", + " draw_flag = 0\n", + " for i in range(len(board)):\n", + " for j in range(len(board)):\n", + " if board[i][j] == 0:\n", + " draw_flag = -1\n", + " return draw_flag\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "1\n", + "1\n", + "-1\n", + "0\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "winner_is_2 = [[2, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "print(winner(winner_is_2))\n", + "\n", + "winner_is_1 = [[1, 2, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 1]]\n", + "print(winner(winner_is_1))\n", + "\n", + "winner_is_also_1 = [[0, 1, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 1]]\n", + "print(winner(winner_is_also_1))\n", + "\n", + "no_winner = [[1, 2, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 2]]\n", + "print(winner(no_winner))\n", + "\n", + "also_no_winner = [[1, 2, 2],\n", + " [2, 1, 1],\n", + " [2, 1, 2]]\n", + "print(winner(also_no_winner))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "tX28FfuoKC5B" + }, + "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", + "execution_count": 13, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Cz4LkMS7KC5F" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the value of n for n*m game board 3\n", + "Enter the value of m for n*m game board 3\n", + " --- --- --- \n", + "| | | | \n", + " --- --- --- \n", + "| | | | \n", + " --- --- --- \n", + "| | | | \n", + " --- --- --- \n" + ] + } + ], + "source": [ + "# Write you solution here\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "FOCaZCjkKC5M" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "H2IL8gw4KC5W" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "-nuhsR_CKC5Y" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "D0Glfwy3KC5k" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "bdTaQwYqKC5r" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ZFBECtCxKC5w" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "TUsJ1xaMKC54" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ZlU8ivpKKC5_" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "rVVJmrSBKC6B" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "l7FOcAthKC6K" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "gxY8SO_mKC6U" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "EwkkOyMzKC6Y" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "wp4zprRlKC6g" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "uwNNWnOKKC6n" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "25_tdn60KC6p" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "61VRLnx7KC62" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "TOdYm8uqKC7B" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "aToFU6M7KC7D" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "rWqXZA8yKC7J" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "tHMry1oWKC7Q" + }, + "source": [ + "*Exercise 10:* Test that your game works for 5x5 Tic Tac Toe. " + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "cezxuBdVKC7S" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "H4eVnxlsKC7Y" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "US43QToKKC7Z" + }, + "outputs": [], + "source": [ + "# Write you solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "HKGF2GEEKC7i" + }, + "outputs": [], + "source": [ + "# Test your solution here" + ] + } + ], + "metadata": { + "colab": { + "name": "Lab-3.ipynb", + "provenance": [] + }, + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Labs/Lab-4/Lab_4-solution-nabin-correected.ipynb b/Labs/Lab-4/Lab_4-solution-nabin-correected.ipynb new file mode 100644 index 0000000..4e645d3 --- /dev/null +++ b/Labs/Lab-4/Lab_4-solution-nabin-correected.ipynb @@ -0,0 +1,1016 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "vOEKs4WOZ0iN" + }, + "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", + "execution_count": 46, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "jq1sEO6pZ0iP" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Value of x is 0.7623145433892383\n" + ] + } + ], + "source": [ + "import random\n", + "x=random.random()\n", + "print (\"The Value of x is\", x)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "KByBvCioZ0iX" + }, + "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", + "execution_count": 47, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Jp52YsR_Z0ib" + }, + "outputs": [], + "source": [ + "# Skeleton\n", + "def generate_uniform(N,x_min,x_max):\n", + " out = []\n", + " for i in range(N):\n", + " out.append(random.randint(x_min,x_max))\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[2, 4, 10, 9, 3, 1, 10, 2, 10, 9]" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "generate_uniform(10,0,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "wvJBapRFZ0i5" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 1, 9, 10, 9, 2, 7, 7, 8]\n", + "Data Type: \n", + "Data Length: 10\n", + "Type of Data Contents: \n", + "Data Minimum: 1\n", + "Data Maximum: 10\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "data=generate_uniform(10,0,10)\n", + "print(data)\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))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "5xel1cFLZ0jD" + }, + "source": [ + "*Exercise 2a:* \n", + "Write a function that computes the mean of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "# Skeleton\n", + "def mean(data):\n", + " m=0\n", + " for i in data:\n", + " m=m+i/len(data)\n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "D0nIaMIgZ0jP" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of Data: 5.8\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "#data =(2,4,6,8,10)\n", + "print (\"Mean of Data:\", mean(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "Mv8oKWDaZ0jX" + }, + "source": [ + "*Exercise 2b:* \n", + "Write a function that computes the variance of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 52, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "C516mxrHZ0jc" + }, + "outputs": [], + "source": [ + "# Skeleton\n", + "def variance(data):\n", + " v=0.\n", + " for i in data:\n", + " v=v +(i-mean(data))**2/len(data)\n", + " return v" + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "8zkbbPKPZ0jj" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Variance of Data: 10.56\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "#data=(2,4,6,8,10)\n", + "print (\"Variance of Data:\", variance(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kQg1FqfUZ0jq" + }, + "source": [ + "## Histogramming" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "niMCYS3QZ0js" + }, + "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", + "execution_count": 54, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def histogram(x,n_bins=10,x_min=None,x_max=None):\n", + " x_min=min(x)\n", + " x_max=max(x)\n", + " bin_size=(x_max-x_min)/n_bins\n", + " hist=[0]*n_bins\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", + " \n", + " bin_edges=[]\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " bin_edges=[round(z,2) for z in bin_edges]\n", + " return hist,bin_edges" + ] + }, + { + "cell_type": "code", + "execution_count": 55, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 1, 0, 0, 0, 2, 1, 2, 1]\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "h,b=histogram(data,10)\n", + "print(h)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "peAvKcAZZ0kC" + }, + "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", + "execution_count": 56, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def draw_histogram(x,n_bins,x_min=None,x_max=None,character=\"#\",max_character_per_line=20):\n", + " x_min=min(x)\n", + " x_max=max(x)\n", + " bin_size=(x_max-x_min)/n_bins\n", + " hist=[0]*n_bins\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", + " \n", + " bin_edges=[]\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " bin_edges=[round(z,2) for z in bin_edges]\n", + " \n", + " for i in range(len(hist)):\n", + " print(\"[\",bin_edges[i],\",\",bin_edges[i+1],\"]\",\":\",int(hist[i])*character)\n", + "\n", + " return hist,bin_edges" + ] + }, + { + "cell_type": "code", + "execution_count": 57, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 1, 9, 10, 9, 2, 7, 7, 8]\n", + "[ 1.0 , 1.9 ] : #\n", + "[ 1.9 , 2.8 ] : ##\n", + "[ 2.8 , 3.7 ] : #\n", + "[ 3.7 , 4.6 ] : \n", + "[ 4.6 , 5.5 ] : \n", + "[ 5.5 , 6.4 ] : \n", + "[ 6.4 , 7.3 ] : ##\n", + "[ 7.3 , 8.2 ] : #\n", + "[ 8.2 , 9.1 ] : ##\n", + "[ 9.1 , 10.0 ] : #\n" + ] + }, + { + "data": { + "text/plain": [ + "([1, 2, 1, 0, 0, 0, 2, 1, 2, 1],\n", + " [1.0, 1.9, 2.8, 3.7, 4.6, 5.5, 6.4, 7.3, 8.2, 9.1, 10.0])" + ] + }, + "execution_count": 57, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "print(data)\n", + "draw_histogram(data,10)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "2EfI49faZ0kS" + }, + "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", + "execution_count": 58, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def where(mylist,myfunction):\n", + " out=[]\n", + " for i,val in enumerate(mylist): \n", + " if myfunction(val):\n", + " out.append(i)\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 59, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 1, 9, 10, 9, 2, 7, 7, 8]\n" + ] + }, + { + "data": { + "text/plain": [ + "[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]" + ] + }, + "execution_count": 59, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "print(data)\n", + "where(data,lambda x:x>0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "chGzRgHyZ0ko" + }, + "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", + "execution_count": 60, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "U8kJPP6BZ0kr" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True True False False False\n", + "False False True True False\n", + "Number of Entries passing F1: 9\n", + "Number of Entries passing F2: 1\n" + ] + } + ], + "source": [ + "def inrange(mymin,mymax):\n", + " def testrange(x):\n", + " return x=mymin\n", + " return testrange\n", + "\n", + "# Examples:\n", + "F1=inrange(0,10)\n", + "F2=inrange(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)))" + ] + }, + { + "cell_type": "code", + "execution_count": 61, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YJS1JRmgZ0kw" + }, + "outputs": [], + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "def even(x):\n", + " return x%2==0\n", + "\n", + "def odd(x):\n", + " return x%2!=0\n", + "\n", + "def greaterthan(y):\n", + " def func(x):\n", + " return x>y\n", + " return func\n", + "\n", + "def lessthan(y):\n", + " def func(x):\n", + " return xy\n", + "greaterthan=lambda x: x>10\n", + "\n", + "#lessthan=lambda x,y: x 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", + "execution_count": 125, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Yr1bmyiuZ0lP" + }, + "outputs": [], + "source": [ + "\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", + " out.append(x_max) \n", + " return out\n", + "\n", + "def generate_function(func,x_min,x_max,N=100):\n", + " out=list()\n", + " x_scan=arange(x_min,x_max,100)\n", + " p_scan=list(map(func,x_scan))\n", + " p_min=min(p_scan)\n", + " p_max=max(p_scan)\n", + " \n", + " while len(out))" + ] + }, + "execution_count": 127, + "metadata": {}, + "output_type": "execute_result" + }, + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAMwUlEQVR4nO3df4xl9V2H8ectI1W0FcxerALjUENJWsS2mWK10Ua22LUQUKMGkhq0xImNVtrY0EWSNv6HpbE21h/ZlJUaCbRSaolEZa1WYgLUXYSyy0IhLcICdZfwh9pqceXjH3ON22F27p17zty735nnlWx2zrl37vmcWebh7Jl7zqaqkCS151tmPYAkaTIGXJIaZcAlqVEGXJIaZcAlqVFz09zYtm3bamFhYZqblKTm7du377mqGqxcP9WALywssHfv3mluUpKal+RfVlvvKRRJapQBl6RGGXBJapQBl6RGGXBJapQBl6RGjQx4kt1JDifZv8pj70tSSbZtzHiSpOMZ5wj8JmDHypVJzgIuAp7seSZJ0hhGBryq7gaeX+WhjwDXAN5QXJJmYKIrMZNcCjxdVQ8mGfXcJWAJYH5+fpLNSRtuYeedM9v2E9dfPLNtq23r/iFmklOA64APjPP8qtpVVYtVtTgYvORSfknShCZ5F8oPAGcDDyZ5AjgTuD/JK/scTJK0tnWfQqmqh4DT/295GPHFqnqux7kkSSOM8zbCW4B7gHOTHEpy1caPJUkaZeQReFVdMeLxhd6mkSSNzSsxJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGjXOv0q/O8nhJPuPWXdDkkeSfDHJZ5KcurFjSpJWGucI/CZgx4p1e4Dzqup84EvAtT3PJUkaYWTAq+pu4PkV6+6qqqPDxXuBMzdgNknSGuZ6eI13Ap883oNJloAlgPn5+Yk3srDzzok/t6snrr94ZtueBb/WUhs6/RAzyXXAUeDm4z2nqnZV1WJVLQ4Ggy6bkyQdY+Ij8CRXApcA26uq+htJkjSOiQKeZAfwfuAtVfX1fkeSJI1jnLcR3gLcA5yb5FCSq4CPAS8H9iR5IMkfb/CckqQVRh6BV9UVq6y+cQNmkSStg1diSlKjDLgkNcqAS1KjDLgkNcqAS1KjDLgkNcqAS1KjDLgkNcqAS1Kj+ridrNSbWd7KVmqNR+CS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1KiRAU+yO8nhJPuPWffdSfYkeWz4+2kbO6YkaaVxjsBvAnasWLcT+FxVnQN8brgsSZqikQGvqruB51esvgz4xPDjTwA/3fNckqQRJr2d7PdU1bMAVfVsktOP98QkS8ASwPz8/ISb25q8taqktWz4DzGraldVLVbV4mAw2OjNSdKWMWnA/zXJ9wIMfz/c30iSpHFMGvA7gCuHH18JfLafcSRJ4xrnbYS3APcA5yY5lOQq4HrgoiSPARcNlyVJUzTyh5hVdcVxHtre8yySpHXwSkxJapQBl6RGGXBJapQBl6RGGXBJapQBl6RGGXBJapQBl6RGGXBJatSkt5OV1DhvVzxdT1x/ce+v6RG4JDXKgEtSowy4JDXKgEtSowy4JDXKgEtSowy4JDXKgEtSowy4JDXKgEtSozoFPMl7kxxIsj/JLUm+ra/BJElrmzjgSc4AfgNYrKrzgJOAy/saTJK0tq6nUOaAb08yB5wCPNN9JEnSOCa+G2FVPZ3kw8CTwH8Cd1XVXSufl2QJWAKYn5+fdHPSpuVdATWpLqdQTgMuA84Gvg/4jiTvWPm8qtpVVYtVtTgYDCafVJL0TbqcQnkr8JWqOlJV/w3cDvxoP2NJkkbpEvAngTclOSVJgO3AwX7GkiSNMnHAq+o+4DbgfuCh4Wvt6mkuSdIInf5Jtar6IPDBnmaRJK2DV2JKUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqM6BTzJqUluS/JIkoNJfqSvwSRJa5vr+PkfBf66qn4uycnAKT3MJEkaw8QBT/IK4MeBXwKoqheAF/oZS5I0Spcj8FcBR4A/SfJDwD7g6qr62rFPSrIELAHMz8932NzsLOy8c9YjSNJLdDkHPge8Afijqno98DVg58onVdWuqlqsqsXBYNBhc5KkY3UJ+CHgUFXdN1y+jeWgS5KmYOKAV9VXgaeSnDtctR14uJepJEkjdX0XyruBm4fvQPky8MvdR5IkjaNTwKvqAWCxp1kkSevglZiS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmN6hzwJCcl+eckf9nHQJKk8fRxBH41cLCH15EkrUOngCc5E7gY+Hg/40iSxtX1CPz3gGuAF3uYRZK0DhMHPMklwOGq2jfieUtJ9ibZe+TIkUk3J0laocsR+JuBS5M8AdwKXJjkz1Y+qap2VdViVS0OBoMOm5MkHWvigFfVtVV1ZlUtAJcDf1dV7+htMknSmnwfuCQ1aq6PF6mqzwOf7+O1JEnj8QhckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckho1ccCTnJXk75McTHIgydV9DiZJWttch889CvxmVd2f5OXAviR7qurhnmaTJK1h4iPwqnq2qu4ffvzvwEHgjL4GkyStrZdz4EkWgNcD963y2FKSvUn2HjlypI/NSZLoIeBJvhP4NPCeqvq3lY9X1a6qWqyqxcFg0HVzkqShTgFP8q0sx/vmqrq9n5EkSePo8i6UADcCB6vqd/sbSZI0ji5H4G8GfhG4MMkDw19v72kuSdIIE7+NsKr+EUiPs0iS1sErMSWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUZ0CnmRHkkeTPJ5kZ19DSZJGmzjgSU4C/gD4KeA1wBVJXtPXYJKktXU5Ar8AeLyqvlxVLwC3Apf1M5YkaZS5Dp97BvDUMcuHgB9e+aQkS8DScPE/kjy6xmtuA57rMFPL3PetyX3fIvI737S43n3//tVWdgl4VllXL1lRtQvYNdYLJnurarHDTM1y3933rcZ9777vXU6hHALOOmb5TOCZbuNIksbVJeD/BJyT5OwkJwOXA3f0M5YkaZSJT6FU1dEkvw78DXASsLuqDnScZ6xTLZuU+741ue9bUy/7nqqXnLaWJDXAKzElqVEGXJIadUIEPMnPJzmQ5MUkiyseu3Z4qf6jSd42qxmnIcnrktyb5IEke5NcMOuZpinJu4d/zgeSfGjW80xbkvclqSTbZj3LtCS5IckjSb6Y5DNJTp31TButz1uQnBABB/YDPwvcfezK4aX5lwOvBXYAfzi8hH+z+hDw21X1OuADw+UtIclPsHwl7/lV9VrgwzMeaaqSnAVcBDw561mmbA9wXlWdD3wJuHbG82yovm9BckIEvKoOVtVqV2heBtxaVd+oqq8Aj7N8Cf9mVcArhh9/F1vrffXvAq6vqm8AVNXhGc8zbR8BrmGVi+E2s6q6q6qODhfvZfl6ks2s11uQnBABX8Nql+ufMaNZpuE9wA1JnmL5CHRTH42s8Grgx5Lcl+Qfkrxx1gNNS5JLgaer6sFZzzJj7wT+atZDbLBem9blUvp1SfK3wCtXeei6qvrs8T5tlXVNH6Gs9XUAtgPvrapPJ/kF4EbgrdOcbyON2Pc54DTgTcAbgU8leVVtkve5jtj33wJ+croTTc843/tJrgOOAjdPc7YZ6LVpUwt4VU0Sok13uf5aX4ckfwpcPVz8c+DjUxlqSkbs+7uA24fB/kKSF1m+4c+Rac23kY6370l+EDgbeDAJLP83fn+SC6rqq1McccOM+t5PciVwCbB9s/wPew29Nu1EP4VyB3B5kpclORs4B/jCjGfaSM8Abxl+fCHw2Axnmba/YHmfSfJq4GS2wJ3qquqhqjq9qhaqaoHlb/A3bJZ4j5JkB/B+4NKq+vqs55mCXm9BMrUj8LUk+Rng94EBcGeSB6rqbVV1IMmngIdZ/uvVr1XV/8xy1g32K8BHk8wB/8X/34Z3K9gN7E6yH3gBuHILHI0JPga8DNgz/BvIvVX1q7MdaeP0fQsSL6WXpEad6KdQJEnHYcAlqVEGXJIaZcAlqVEGXJIaZcAlqVEGXJIa9b+nl+V7WC2EGAAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "%matplotlib inline\n", + "import matplotlib.pyplot as plt\n", + "\n", + "plt.hist(generate_function(test_func,0,10))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "S8ACDLiPZ0lY" + }, + "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", + "execution_count": 88, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "2DxoiyJkZ0la" + }, + "outputs": [], + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 89, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 7, 6, 9, 0, 7, 0, 2, 0, 9, 7, 10, 8, 4, 5, 4, 0, 7, 4, 4, 3, 8, 9, 1, 1, 4, 3, 10, 1, 2, 0, 5, 5, 10, 2, 4, 3, 0, 5, 5, 10, 7, 10, 4, 6, 2, 6, 2, 2, 5, 9, 4, 6, 10, 4, 7, 10, 5, 5, 10, 3, 7, 0, 7, 0, 4, 0, 6, 1, 3, 6, 9, 9, 2, 3, 3, 5, 6, 6, 8, 4, 3, 8, 6, 5, 1, 8, 6, 5, 7, 7, 3, 4, 4, 1, 0, 2, 3, 1, 3]\n" + ] + } + ], + "source": [ + "test2=generate_function(g1,0,10)\n", + "print(test2)\n", + "#test3=generate_function(g2,0,10)\n", + "#print(test3)" + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXAAAAD4CAYAAAD1jb0+AAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAMr0lEQVR4nO3dcayddX3H8fdnrUaLGjA9OG3pLi6EzZAtmJsNJXELlaUbBPxjSyDBMEdy/9kUjQsr8w/+7TLjNNni0gBCIqlZKotEpqNBDVnCyG4LjkJxGOxKsdpLyKZzS5D43R/3mFwvbc+553nOPf3d+34l5J7znNPz+z5p++bpc89zbqoKSVJ7fmnWA0iSJmPAJalRBlySGmXAJalRBlySGrV1PRfbvn17zc3NreeSktS8w4cPv1xVg9Xb1zXgc3NzLC4urueSktS8JP95pu2eQpGkRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRq3rlZiSNEtzex+e2drH913X+2t6BC5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjRoZ8CT3Jjmd5OgZHvvzJJVk+3TGkySdzThH4PcBe1ZvTHIJcC1woueZJEljGBnwqnoMeOUMD/0NcAdQfQ8lSRptonPgSW4AXqqqb/c8jyRpTGv+NMIk24BPAb835vMXgAWAXbt2rXU5SdJZTHIE/qvApcC3kxwHdgJHkvzymZ5cVfurar6q5geDweSTSpJ+wZqPwKvqaeDin98fRny+ql7ucS5J0gjjvI3wAPA4cHmSk0lum/5YkqRRRh6BV9XNIx6f620aSdLYvBJTkhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUWu+lF6aprm9D89k3eP7rpvJulIXHoFLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1yoBLUqMMuCQ1apwfanxvktNJjq7Y9tdJnkvy70n+McmF0x1TkrTaOEfg9wF7Vm07BFxRVb8B/AdwZ89zSZJGGBnwqnoMeGXVtkeq6rXh3X8Fdk5hNknSOfRxDvxPgK+d7cEkC0kWkywuLS31sJwkCToGPMmngNeAB872nKraX1XzVTU/GAy6LCdJWmHizwNPcitwPbC7qqq/kSRJ45go4En2AH8B/E5V/W+/I0mSxjHO2wgPAI8Dlyc5meQ24G+BtwKHkjyV5O+nPKckaZWRR+BVdfMZNt8zhVkkSWvglZiS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNMuCS1CgDLkmNmvizULRxze19eNYjrLtZ7vPxfdfNbG21zSNwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRo3zQ43vTXI6ydEV296e5FCS54dfL5rumJKk1cY5Ar8P2LNq217g0aq6DHh0eF+StI5GBryqHgNeWbX5RuD+4e37gQ/1PJckaYRJP43wHVV1CqCqTiW5+GxPTLIALADs2rVrwuX8tDhtXJvx0x/9O9WPqX8Ts6r2V9V8Vc0PBoNpLydJm8akAf9hkncCDL+e7m8kSdI4Jg34Q8Ctw9u3Al/pZxxJ0rjGeRvhAeBx4PIkJ5PcBuwDrk3yPHDt8L4kaR2N/CZmVd18lod29zyLJGkNvBJTkhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUQZckhplwCWpUZ0CnuQTSZ5JcjTJgSRv6mswSdK5TRzwJDuAjwHzVXUFsAW4qa/BJEnn1vUUylbgzUm2AtuA73cfSZI0jpE/lf5squqlJJ8GTgD/BzxSVY+sfl6SBWABYNeuXZMutynN7X141iNIOo91OYVyEXAjcCnwLuCCJLesfl5V7a+q+aqaHwwGk08qSfoFXU6hfBD4XlUtVdVPgQeB9/czliRplC4BPwFclWRbkgC7gWP9jCVJGmXigFfVE8BB4Ajw9PC19vc0lyRphIm/iQlQVXcBd/U0iyRpDbwSU5IaZcAlqVEGXJIaZcAlqVEGXJIaZcAlqVEGXJIaZcAlqVGdLuTZLPxUQEnnI4/AJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGmXAJalRBlySGtUp4EkuTHIwyXNJjiV5X1+DSZLOretnoXwO+HpV/WGSNwLbephJkjSGiQOe5G3AB4A/BqiqV4FX+xlLkjRKl1Mo7waWgC8keTLJ3UkuWP2kJAtJFpMsLi0tdVhOkrRSl4BvBd4LfL6qrgR+Auxd/aSq2l9V81U1PxgMOiwnSVqpS8BPAier6onh/YMsB12StA4mDnhV/QB4Mcnlw027gWd7mUqSNFLXd6F8FHhg+A6UF4CPdB9JkjSOTgGvqqeA+Z5mkSStgVdiSlKjDLgkNcqAS1KjDLgkNcqAS1KjDLgkNcqAS1KjDLgkNarrlZiStGZzex+e9QgbgkfgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktSozgFPsiXJk0m+2sdAkqTx9HEEfjtwrIfXkSStQaeAJ9kJXAfc3c84kqRxdT0C/yxwB/CzHmaRJK3BxAFPcj1wuqoOj3jeQpLFJItLS0uTLidJWqXLEfjVwA1JjgNfAq5J8sXVT6qq/VU1X1Xzg8Ggw3KSpJUmDnhV3VlVO6tqDrgJ+EZV3dLbZJKkc/J94JLUqF5+Ik9VfQv4Vh+vJUkaj0fgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktQoAy5JjTLgktSoiQOe5JIk30xyLMkzSW7vczBJ0rl1+aHGrwGfrKojSd4KHE5yqKqe7Wk2SdI5THwEXlWnqurI8PaPgWPAjr4GkySdWy/nwJPMAVcCT5zhsYUki0kWl5aW+lhOkkQPAU/yFuDLwMer6kerH6+q/VU1X1Xzg8Gg63KSpKFOAU/yBpbj/UBVPdjPSJKkcXR5F0qAe4BjVfWZ/kaSJI2jyxH41cCHgWuSPDX87w96mkuSNMLEbyOsqn8B0uMskqQ18EpMSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWqUAZekRhlwSWpUp4An2ZPkO0m+m2RvX0NJkkabOOBJtgB/B/w+8B7g5iTv6WswSdK5dTkC/y3gu1X1QlW9CnwJuLGfsSRJo2zt8Gt3AC+uuH8S+O3VT0qyACwM7/5Pku9MuN524OUJf22r3OfNwX3eBPJXnfb5V860sUvAc4Zt9boNVfuB/R3WWV4sWayq+a6v0xL3eXNwnzeHaexzl1MoJ4FLVtzfCXy/2ziSpHF1Cfi/AZcluTTJG4GbgIf6GUuSNMrEp1Cq6rUkfwb8M7AFuLeqnultstfrfBqmQe7z5uA+bw6973OqXnfaWpLUAK/ElKRGGXBJalQTAd9sl+wnuSTJN5McS/JMkttnPdN6SLIlyZNJvjrrWdZDkguTHEzy3PD3+n2znmnaknxi+Gf6aJIDSd4065n6luTeJKeTHF2x7e1JDiV5fvj1oj7WOu8Dvkkv2X8N+GRV/TpwFfCnm2CfAW4Hjs16iHX0OeDrVfVrwG+ywfc9yQ7gY8B8VV3B8psfbprtVFNxH7Bn1ba9wKNVdRnw6PB+Z+d9wNmEl+xX1amqOjK8/WOW/2LvmO1U05VkJ3AdcPesZ1kPSd4GfAC4B6CqXq2q/5rtVOtiK/DmJFuBbWzAa0eq6jHglVWbbwTuH96+H/hQH2u1EPAzXbK/oWO2UpI54ErgidlOMnWfBe4AfjbrQdbJu4El4AvD00Z3J7lg1kNNU1W9BHwaOAGcAv67qh6Z7VTr5h1VdQqWD9CAi/t40RYCPtYl+xtRkrcAXwY+XlU/mvU805LkeuB0VR2e9SzraCvwXuDzVXUl8BN6+mf1+Wp43vdG4FLgXcAFSW6Z7VRtayHgm/KS/SRvYDneD1TVg7OeZ8quBm5IcpzlU2TXJPnibEeaupPAyar6+b+sDrIc9I3sg8D3qmqpqn4KPAi8f8YzrZcfJnknwPDr6T5etIWAb7pL9pOE5XOjx6rqM7OeZ9qq6s6q2llVcyz//n6jqjb0kVlV/QB4Mcnlw027gWdnONJ6OAFclWTb8M/4bjb4N25XeAi4dXj7VuArfbxol08jXBczuGT/fHA18GHg6SRPDbf9ZVX90wxnUv8+CjwwPDB5AfjIjOeZqqp6IslB4AjL77R6kg14SX2SA8DvAtuTnATuAvYB/5DkNpb/R/ZHvazlpfSS1KYWTqFIks7AgEtSowy4JDXKgEtSowy4JDXKgEtSowy4JDXq/wGsV84Ywz0mOgAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + } + ], + "source": [ + "plt.hist(test2)\n", + "plt.show()" + ] + }, + { + "cell_type": "code", + "execution_count": 90, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.759999999999999 8.922399999999996\n" + ] + } + ], + "source": [ + "m=mean(test2)\n", + "v=variance(test2)\n", + "print(m,v)" + ] + }, + { + "cell_type": "code", + "execution_count": 91, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 2, 3, 1, 8, 8, 0, 0, 10, 4, 3, 10, 2, 1, 3, 5, 6, 5, 7, 2, 5, 0, 4, 8, 5, 2, 3, 4, 8, 5, 1, 7, 0, 5, 3, 7, 2, 1, 5, 6, 8, 10, 6, 2, 4, 8, 8, 0, 3, 10, 10, 6, 7, 4, 8, 9, 9, 8, 6, 0, 3, 5, 8, 3, 8, 0, 9, 9, 2, 0, 10, 7, 4, 10, 3, 3, 10, 3, 4, 3, 0, 8, 2, 1, 6, 2, 0, 7, 9, 0, 3, 10, 9, 2, 2, 5, 5, 6, 0, 0]\n" + ] + } + ], + "source": [ + "g2=gaussian(5.448275862068969, 9.764565992865645)\n", + "result=generate_function(g2,0,10)\n", + "print(result)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 92, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4.699999999999996 10.230000000000011\n" + ] + } + ], + "source": [ + "m=mean(result)\n", + "v=variance(result)\n", + "print(m,v)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "AtfVcDd4Z0lf" + }, + "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", + "execution_count": 130, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "pM5RLjRgZ0li" + }, + "outputs": [], + "source": [ + "def integrate(func, x_min, x_max, n_points=1000):\n", + " out = list()\n", + " x_scan=arange(x_min,x_max,100)\n", + " p_scan=list(map(func,x_scan))\n", + " p_min=min(p_scan)\n", + " p_max=max(p_scan)\n", + " \n", + " count=0\n", + " while len(out)\n", + "Data Length: 10\n", + "Type of Data Contents: \n", + "Data Minimum: 0\n", + "Data Maximum: 8\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "data=generate_uniform(10,0,10)\n", + "print(data)\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))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "5xel1cFLZ0jD" + }, + "source": [ + "*Exercise 2a:* \n", + "Write a function that computes the mean of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 168, + "metadata": {}, + "outputs": [], + "source": [ + "# Skeleton\n", + "def mean(Data):\n", + " m=0\n", + " for i in Data:\n", + " m=m+i/len(Data)\n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 169, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "D0nIaMIgZ0jP" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of Data: 3.500000000000001\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "#data =(2,4,6,8,10)\n", + "print (\"Mean of Data:\", mean(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "Mv8oKWDaZ0jX" + }, + "source": [ + "*Exercise 2b:* \n", + "Write a function that computes the variance of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 170, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "C516mxrHZ0jc" + }, + "outputs": [], + "source": [ + "# Skeleton\n", + "def variance(Data):\n", + " v=0.\n", + " for i in Data:\n", + " v=v +(i-mean(Data))**2/len(Data)\n", + " return v" + ] + }, + { + "cell_type": "code", + "execution_count": 171, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "8zkbbPKPZ0jj" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Variance of Data: 9.65\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "#data=(2,4,6,8,10)\n", + "print (\"Variance of Data:\", variance(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kQg1FqfUZ0jq" + }, + "source": [ + "## Histogramming" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "niMCYS3QZ0js" + }, + "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", + "execution_count": 130, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def histogram(x,n_bins=10,x_min=None,x_max=None):\n", + " x_min=min(x)\n", + " x_max=max(x)\n", + " bin_size=(x_max-x_min)/n_bins\n", + " hist=[0]*n_bins\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", + " \n", + " bin_edges=[]\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " bin_edges=[round(z,2) for z in bin_edges]\n", + " return hist,bin_edges" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 2, 0, 1, 1, 0, 0, 0, 3]\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "h,b=histogram(data,10)\n", + "print(h)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "peAvKcAZZ0kC" + }, + "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", + "execution_count": 134, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def draw_histogram(x,n_bins,x_min=None,x_max=None,character=\"#\",max_character_per_line=20):\n", + " x_min=min(x)\n", + " x_max=max(x)\n", + " bin_size=(x_max-x_min)/n_bins\n", + " hist=[0]*n_bins\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", + " \n", + " bin_edges=[]\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " bin_edges=[round(z,2) for z in bin_edges]\n", + " \n", + " for i in range(len(hist)):\n", + " print(\"[\",bin_edges[i],\",\",bin_edges[i+1],\"]\",\":\",int(hist[i])*character)\n", + "\n", + " return hist,bin_edges" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 2, 2, 8, 1, 8, 1, 8, 4, 1]\n", + "[ 0.0 , 0.8 ] : #\n", + "[ 0.8 , 1.6 ] : ###\n", + "[ 1.6 , 2.4 ] : ##\n", + "[ 2.4 , 3.2 ] : \n", + "[ 3.2 , 4.0 ] : #\n", + "[ 4.0 , 4.8 ] : #\n", + "[ 4.8 , 5.6 ] : \n", + "[ 5.6 , 6.4 ] : \n", + "[ 6.4 , 7.2 ] : \n", + "[ 7.2 , 8.0 ] : ###\n" + ] + }, + { + "data": { + "text/plain": [ + "([1, 3, 2, 0, 1, 1, 0, 0, 0, 3],\n", + " [0.0, 0.8, 1.6, 2.4, 3.2, 4.0, 4.8, 5.6, 6.4, 7.2, 8.0])" + ] + }, + "execution_count": 135, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "print(data)\n", + "draw_histogram(data,10)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "2EfI49faZ0kS" + }, + "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", + "execution_count": 139, + "metadata": {}, + "outputs": [], + "source": [ + "# Solution\n", + "def where(mylist,myfunction):\n", + " out=[]\n", + " for i,val in enumerate(mylist): \n", + " if myfunction(val):\n", + " out.append(i)\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 2, 2, 8, 1, 8, 1, 8, 4, 1]\n" + ] + }, + { + "data": { + "text/plain": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9]" + ] + }, + "execution_count": 141, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "print(data)\n", + "where(data,lambda x:x>0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "chGzRgHyZ0ko" + }, + "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", + "execution_count": 142, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "U8kJPP6BZ0kr" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True True False False False\n", + "False False True True False\n", + "Number of Entries passing F1: 10\n", + "Number of Entries passing F2: 0\n" + ] + } + ], + "source": [ + "def inrange(mymin,mymax):\n", + " def testrange(x):\n", + " return x=mymin\n", + " return testrange\n", + "\n", + "# Examples:\n", + "F1=inrange(0,10)\n", + "F2=inrange(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)))" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YJS1JRmgZ0kw" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True False True False True\n", + "False True False True False\n", + "False False False False True\n", + "True True True False False\n", + "False False False True False\n", + "True False False True False\n" + ] + } + ], + "source": [ + "### BEGIN SOLUTION\n", + "\n", + "def even(x):\n", + " return x%2==0\n", + " return even\n", + "\n", + "def odd(x):\n", + " return x%2!=0\n", + " return odd\n", + "\n", + "def greaterthan(x,y):\n", + " return x>y\n", + " return greaterthan\n", + "\n", + "def lessthan(x,y):\n", + " return xy\n", + "\n", + "lessthan=lambda x,y: x 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", + "execution_count": 150, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Yr1bmyiuZ0lP" + }, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 9)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"\"\u001b[1;36m, line \u001b[1;32m9\u001b[0m\n\u001b[1;33m if p=func(x):\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "import random\n", + "\n", + "def generate_function(func,x_min,x_max,N=1000):\n", + " out = []\n", + " i=0\n", + " while i<=N:\n", + " x=random.choice(range(x_min,x_max))\n", + " p=random.choice(range((x_min,x_max))\n", + " if p<=func(x):\n", + " out.append(x)\n", + " i+=1\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 159, + "metadata": {}, + "outputs": [], + "source": [ + "import random\n", + "def generate_function(func,x_min,x_max,N=1000):\n", + " out=[]\n", + " i=0\n", + " while i<=N:\n", + " x=random.randint(x_min,x_max)\n", + " p=random.randint(x_min,x_max)\n", + " if p<=func(x):\n", + " out.append(x)\n", + " i+=1\n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 160, + "metadata": {}, + "outputs": [], + "source": [ + "# A test function\n", + "def test_func(x,a=1,b=1):\n", + " return abs(a*x+b)" + ] + }, + { + "cell_type": "code", + "execution_count": 161, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[10, 3, 7, 10, 6, 8, 3, 8, 10, 3, 1, 9, 8, 3, 2, 3, 10, 8, 1, 8, 8, 8, 9, 10, 7, 7, 9, 10, 1, 9, 10, 8, 8, 5, 5, 1, 10, 10, 2, 6, 7, 6, 2, 8, 4, 3, 1, 8, 8, 6, 8, 5, 7, 5, 4, 10, 10, 10, 10, 6, 6, 3, 8, 7, 6, 8, 9, 8, 9, 8, 6, 5, 10, 8, 5, 8, 0, 5, 5, 1, 10, 8, 0, 10, 9, 7, 5, 9, 7, 10, 9, 8, 6, 3, 8, 0, 9, 0, 8, 4, 9, 7, 6, 8, 7, 3, 6, 7, 6, 9, 7, 6, 8, 9, 9, 8, 9, 9, 8, 1, 3, 4, 9, 8, 5, 3, 10, 10, 8, 6, 5, 3, 5, 5, 9, 8, 10, 2, 9, 7, 9, 8, 7, 10, 4, 9, 9, 8, 8, 5, 3, 5, 9, 8, 9, 6, 8, 4, 7, 5, 5, 8, 1, 8, 2, 9, 10, 3, 5, 9, 8, 10, 8, 9, 10, 7, 2, 0, 7, 8, 9, 7, 4, 10, 3, 9, 10, 5, 9, 10, 10, 7, 8, 10, 6, 5, 7, 3, 9, 10, 10, 6, 7, 7, 2, 5, 6, 8, 6, 3, 6, 8, 1, 5, 8, 5, 9, 4, 9, 3, 5, 9, 9, 6, 5, 10, 8, 8, 7, 8, 2, 5, 9, 7, 3, 10, 5, 3, 3, 10, 10, 1, 10, 8, 1, 9, 10, 9, 5, 10, 3, 4, 6, 9, 8, 2, 9, 8, 9, 5, 6, 0, 8, 6, 4, 6, 8, 4, 10, 3, 6, 8, 3, 9, 8, 4, 2, 9, 6, 7, 9, 8, 2, 8, 9, 7, 4, 10, 3, 8, 10, 8, 8, 8, 6, 4, 4, 1, 1, 10, 6, 9, 7, 8, 6, 10, 10, 4, 8, 6, 3, 8, 8, 1, 8, 9, 5, 10, 10, 8, 9, 10, 6, 0, 3, 9, 7, 6, 7, 5, 5, 1, 7, 10, 10, 9, 9, 6, 10, 8, 9, 9, 3, 2, 10, 4, 10, 9, 5, 10, 9, 3, 7, 4, 8, 7, 9, 9, 3, 7, 9, 6, 8, 9, 7, 10, 4, 10, 5, 4, 6, 8, 8, 9, 3, 6, 3, 4, 3, 8, 0, 9, 9, 5, 7, 7, 9, 6, 9, 4, 0, 9, 2, 5, 10, 5, 1, 10, 3, 10, 9, 9, 4, 7, 3, 8, 2, 10, 9, 5, 6, 7, 1, 8, 6, 7, 0, 8, 9, 8, 3, 8, 7, 6, 6, 3, 9, 4, 9, 3, 5, 3, 7, 9, 8, 6, 7, 7, 6, 3, 6, 4, 8, 5, 8, 9, 1, 10, 8, 9, 8, 4, 8, 8, 1, 10, 9, 4, 9, 8, 7, 1, 9, 8, 2, 8, 8, 9, 4, 9, 7, 3, 1, 10, 0, 10, 5, 3, 7, 7, 7, 3, 8, 6, 9, 4, 10, 9, 1, 7, 9, 6, 4, 3, 6, 2, 7, 5, 3, 7, 9, 7, 8, 8, 8, 4, 4, 8, 9, 5, 5, 10, 3, 7, 8, 3, 10, 9, 3, 7, 3, 2, 9, 4, 4, 7, 0, 7, 8, 9, 5, 6, 7, 7, 9, 7, 8, 10, 10, 10, 6, 6, 9, 3, 7, 8, 9, 9, 10, 10, 8, 6, 5, 6, 3, 2, 8, 8, 9, 5, 9, 1, 7, 6, 5, 9, 9, 4, 6, 6, 8, 4, 6, 1, 10, 10, 3, 8, 10, 10, 2, 10, 8, 5, 5, 8, 5, 8, 9, 8, 5, 4, 8, 6, 8, 6, 1, 8, 10, 10, 8, 2, 4, 7, 5, 8, 6, 6, 8, 10, 10, 7, 10, 10, 9, 7, 7, 7, 0, 10, 7, 8, 10, 6, 6, 3, 2, 6, 8, 7, 9, 6, 0, 0, 10, 4, 4, 5, 9, 10, 8, 4, 6, 10, 9]\n" + ] + } + ], + "source": [ + "#test_func(10)\n", + "test=generate_function(test_func,0,10)\n", + "print(test)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "S8ACDLiPZ0lY" + }, + "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", + "execution_count": 162, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "2DxoiyJkZ0la" + }, + "outputs": [], + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 166, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[9, 2, 9, 7, 10, 0, 5, 1, 8, 10, 7, 7, 8, 10, 1, 7, 9, 0, 5, 8, 0, 9, 10, 4, 9, 6, 4, 4, 9, 6, 0, 2, 3, 8, 6, 7, 6, 4, 7, 10, 9, 0, 2, 8, 1, 0, 0, 9, 7, 2, 6, 5, 9, 3, 6, 6, 8, 9, 2, 6, 8, 4, 3, 9, 9, 4, 7, 5, 4, 7, 0, 6, 0, 3, 6, 5, 9, 1, 5, 1, 9, 4, 9, 2, 6, 8, 5]\n" + ] + } + ], + "source": [ + "test2=generate_function(g1,0,10)\n", + "print(test2)\n", + "#test3=generate_function(g2,0,10)\n", + "#print(test3)" + ] + }, + { + "cell_type": "code", + "execution_count": 173, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5.448275862068969 9.764565992865645\n" + ] + } + ], + "source": [ + "m=mean(test2)\n", + "v=variance(test2)\n", + "print(m,v)" + ] + }, + { + "cell_type": "code", + "execution_count": 178, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 4, 3, 0, 0, 8, 7, 3, 7, 9, 5, 2, 2, 10, 1, 2, 3, 0, 4, 8, 4, 3, 6, 9, 0, 4, 8, 5, 8, 7, 10, 6, 3, 8, 4, 6, 9, 6, 6, 8, 9, 3, 6, 8, 7, 1, 8, 9, 0, 10, 0, 6, 7, 10, 9, 1, 7, 7, 8, 8, 0, 9, 0, 3, 6, 0, 3, 9, 5, 2, 1, 10, 9, 4, 1, 9, 4, 10, 2, 10, 4, 10, 3, 10, 3, 6, 3, 8, 3, 7, 10, 0, 3, 5, 0]\n" + ] + } + ], + "source": [ + "g2=gaussian(5.448275862068969, 9.764565992865645)\n", + "result=generate_function(g2,0,10)\n", + "print(result)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 179, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5.1999999999999975 10.854736842105268\n" + ] + } + ], + "source": [ + "m=mean(result)\n", + "v=variance(result)\n", + "print(m,v)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "AtfVcDd4Z0lf" + }, + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "pM5RLjRgZ0li" + }, + "outputs": [], + "source": [ + "def integrate(func, x_min, x_max, n_points=1000):\n", + " \n", + " return integral" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Ey6fyDK-Z0lp" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Lab-4.ipynb", + "provenance": [] + }, + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} diff --git a/Labs/Lab-5/Lab-5-solution.ipynb b/Labs/Lab-5/Lab-5-solution.ipynb new file mode 100644 index 0000000..935fa1d --- /dev/null +++ b/Labs/Lab-5/Lab-5-solution.ipynb @@ -0,0 +1,1038 @@ +{ + "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": 323, + "metadata": {}, + "outputs": [], + "source": [ + "class counter:\n", + " def __init__(self, max_val):\n", + " self.max_val=max_val\n", + " self.cur_val=1\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", + " def reset (self):\n", + " self.cur_val=1\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 324, + "metadata": {}, + "outputs": [], + "source": [ + "new_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 325, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 325, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_counter.cur_val" + ] + }, + { + "cell_type": "code", + "execution_count": 326, + "metadata": {}, + "outputs": [], + "source": [ + "new_counter.increment()\n", + "new_counter.increment()\n", + "new_counter.increment()" + ] + }, + { + "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": 327, + "metadata": {}, + "outputs": [], + "source": [ + "class counter:\n", + " def __init__(self, max_val):\n", + " self.__max_val=max_val\n", + " self.__cur_val=1\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", + " def reset (self):\n", + " self.__cur_val=1\n", + " \n", + " def maximum(self):\n", + " return self.__max_val\n", + " \n", + " def current(self):\n", + " return self.__cur_val\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 328, + "metadata": {}, + "outputs": [], + "source": [ + "new_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 329, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "3" + ] + }, + "execution_count": 329, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_counter.maximum()" + ] + }, + { + "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": 330, + "metadata": {}, + "outputs": [], + "source": [ + "class rectangle:\n", + " def __init__(self,width,length,x,y): # x,y is the co-ordinate of the bottom left corner\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 get_coordinate(self):\n", + " return self.__x,self.__y\n", + " \n", + " def get_width(self):\n", + " return self.__width\n", + " \n", + " def get_length(self):\n", + " return self.__length" + ] + }, + { + "cell_type": "code", + "execution_count": 331, + "metadata": {}, + "outputs": [], + "source": [ + "new_rectangle=rectangle(4,5,0,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 332, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "20" + ] + }, + "execution_count": 332, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_rectangle.area()" + ] + }, + { + "cell_type": "code", + "execution_count": 333, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "18" + ] + }, + "execution_count": 333, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_rectangle.perimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 334, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 0)" + ] + }, + "execution_count": 334, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_rectangle.get_coordinate()" + ] + }, + { + "cell_type": "code", + "execution_count": 335, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "4" + ] + }, + "execution_count": 335, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_rectangle.get_width()" + ] + }, + { + "cell_type": "code", + "execution_count": 336, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 336, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_rectangle.get_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": 337, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "class circle:\n", + " def __init__(self,radius,x,y): # x,y is the co-ordinate of the centre\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 get_centre(self):\n", + " return self.__x,self.__y\n", + " \n", + " def get_radius(self):\n", + " return self.__radius\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 338, + "metadata": {}, + "outputs": [], + "source": [ + "new_circle=circle(2,0,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 339, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.566370614359172" + ] + }, + "execution_count": 339, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_circle.area()" + ] + }, + { + "cell_type": "code", + "execution_count": 340, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.566370614359172" + ] + }, + "execution_count": 340, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_circle.perimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 341, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 0)" + ] + }, + "execution_count": 341, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_circle.get_centre()" + ] + }, + { + "cell_type": "code", + "execution_count": 342, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "2" + ] + }, + "execution_count": 342, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "new_circle.get_radius()" + ] + }, + { + "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": 343, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "class geometry:\n", + " def __init__(self,x,y): # x,y is the co-ordinate of the bottom left corner for rectangle and cintre for circel\n", + " self.x=x\n", + " self.y=y\n", + " \n", + " def get_cordinate(self):\n", + " return NotImplementedError\n", + " \n", + " def get_area(self):\n", + " return NotImplementedError\n", + " \n", + " def get_perimeter(self):\n", + " return NotImplementedError\n", + " \n", + "class rectangle(geometry):\n", + " def __init__(self,x,y,l,w):\n", + " geometry.__init__(self,x,y)\n", + " self.l=l\n", + " self.w=w\n", + " \n", + " def get_cordinate(self):\n", + " return(self.x ,self.y)\n", + " \n", + " def get_area(self):\n", + " return self.l*self.w\n", + " \n", + " def get_perimeter(self):\n", + " return 2*(self.l+self.w)\n", + " \n", + "class circle(geometry):\n", + " def __init__(self,x,y,r):\n", + " geometry.__init__(self,x,y)\n", + " self.r=r\n", + " \n", + " def get_cordinate(self):\n", + " return(self.x ,self.y)\n", + " \n", + " def get_area(self):\n", + " return (math.pi*self.r**2)\n", + " \n", + " def get_perimeter(self):\n", + " return (2*math.pi*self.r)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 344, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "NotImplementedError" + ] + }, + "execution_count": 344, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data1=geometry(0,0)\n", + "data1.get_cordinate()\n", + "#data1.get_area()\n", + "#data1.get_perimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 345, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 0)" + ] + }, + "execution_count": 345, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data2=rectangle(0,0,2,2)\n", + "data2.get_cordinate()\n", + "#data2.get_area()\n", + "#data2.get_perimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 346, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 0)" + ] + }, + "execution_count": 346, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data3=circle(0,0,2)\n", + "data3.get_cordinate()\n", + "#data3.get_area()\n", + "#data3.get_perimeter()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "6. Implement an analogous triangle class." + ] + }, + { + "cell_type": "code", + "execution_count": 347, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "\n", + "class traingle(geometry): # x,y is the co-ordinate of the bottom left corner of traingle**\n", + " def __init__(self,x,y,x2,y2,x3,y3): # **while x2,y2 and x3,y3 are cordinates of other two corners \n", + " geometry.__init__(self,x,y)\n", + " self.x2=x2\n", + " self.y2=y2\n", + " self.x3=x3\n", + " self.y3=y3\n", + " \n", + " def get_cordinate(self):\n", + " return(self.x ,self.y)\n", + " \n", + " def get_area(self):\n", + " return abs((self.x*(self.y2-self.y3)+self.x2*(self.y3-self.y)+self.x3*(self.y-self.y2))/2)\n", + " \n", + " def get_perimeter(self):\n", + " l1=math.sqrt(((self.x-self.x2)**2)+((self.y-self.y2)**2))\n", + " l2=math.sqrt(((self.x-self.x3)**2)+((self.y-self.y3)**2))\n", + " l3=math.sqrt(((self.x3-self.x2)**2)+((self.y3-self.y2)**2))\n", + " return (l1+l2+l3)" + ] + }, + { + "cell_type": "code", + "execution_count": 348, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.47213595499958" + ] + }, + "execution_count": 348, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data4=traingle(0,0,2,0,1,2)\n", + "data4.get_cordinate()\n", + "data4.get_area()\n", + "data4.get_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": 417, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "#linked with Q5\n", + "class coordinate_rectangle(rectangle):\n", + " def __init__(self,x,y,l,w,p,q): #p,q are the x,y co-ordinate of the point to be tested \n", + " rectangle.__init__(self,x,y,l,w)\n", + " self.p=p\n", + " self.q=q # calculating the coordinates of the corner of the rectangle for**\n", + " self.x2=self.x+self.l #**the given bottom left coordinate, length and width\n", + " self.y2=self.y\n", + " self.x3=self.x+self.l\n", + " self.y3=self.y+self.w\n", + " self.x4=self.x\n", + " self.y4=self.y+self.w\n", + " #return (self.x,self.y,self.x2,self.y2,self.x3,self.y3,self.x4,self.y4)\n", + " \n", + " def test_location(self):\n", + " ABC=abs((self.x*(self.y2-self.y3)+self.x2*(self.y3-self.y)+self.x3*(self.y-self.y2))/2)\n", + " ACD=abs((self.x*(self.y3-self.y4)+self.x3*(self.y4-self.y)+self.x4*(self.y-self.y3))/2)\n", + " \n", + " A1=abs((self.p*(self.y-self.y2)+self.x*(self.y2-self.q)+self.x2*(self.q-self.y))/2)\n", + " A2=abs((self.p*(self.y2-self.y3)+self.x2*(self.y3-self.q)+self.x3*(self.q-self.y2))/2)\n", + " A3=abs((self.p*(self.y3-self.y4)+self.x3*(self.y4-self.q)+self.x4*(self.q-self.y3))/2)\n", + " A4=abs((self.p*(self.y4-self.y)+self.x4*(self.y-self.q)+self.x*(self.q-self.y4))/2)\n", + " \n", + "\n", + " if (ABC+ACD)>=(A1+A2+A3+A4):\n", + " return \"The coordinate is located within the Rectangle\"\n", + " else:\n", + " return \"The coordinate is NOT located within the Rectangle\"" + ] + }, + { + "cell_type": "code", + "execution_count": 418, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The coordinate is NOT located within the Rectangle'" + ] + }, + "execution_count": 418, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data5=coordinate_rectangle(0,0,2,2,10,10)\n", + "data5.test_location()" + ] + }, + { + "cell_type": "code", + "execution_count": 351, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "#linked with Q5\n", + "class coordinate_circle(circle):\n", + " def __init__(self,x,y,r,p,q): #p,q are the x,y co-ordinate of the point to be tested\n", + " circle.__init__(self,x,y,r)\n", + " self.p=p\n", + " self.q=q\n", + " \n", + " def test_location(self):\n", + " d=math.sqrt((self.x-self.p)**2+((self.y-self.q)**2))\n", + " if d<=self.r:\n", + " return \"The coordinate is located within Circle\"\n", + " else:\n", + " return \"The coordinate is NOT located within Circle\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": 352, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The coordinate is located within Circle'" + ] + }, + "execution_count": 352, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data6=coordinate_circle(0,0,10,2,2)\n", + "data6.test_location()" + ] + }, + { + "cell_type": "code", + "execution_count": 353, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "#linked with Q6\n", + "class coordinate_traingle(traingle):\n", + " def __init__(self,x,y,x2,y2,x3,y3,p,q): #p,q are the x,y co-ordinate of the point to be tested\n", + " traingle.__init__(self,x,y,x2,y2,x3,y3)\n", + " self.p=p\n", + " self.q=q\n", + " \n", + " def test_location(self):\n", + " ABC=abs((self.x*(self.y2-self.y3)+self.x2*(self.y3-self.y)+self.x3*(self.y-self.y2))/2)\n", + " \n", + " A1=abs((self.p*(self.y-self.y2)+self.x*(self.y2-self.q)+self.x2*(self.q-self.y))/2)\n", + " A2=abs((self.p*(self.y2-self.y3)+self.x2*(self.y3-self.q)+self.x3*(self.q-self.y2))/2)\n", + " A3=abs((self.p*(self.y3-self.y)+self.x3*(self.y-self.q)+self.x*(self.q-self.y3))/2)\n", + " \n", + " if ABC>=(A1+A2+A3):\n", + " return \"The coordinate is located within the Traingle\"\n", + " else:\n", + " return \"The coordinate is NOT located within the Traingle\"" + ] + }, + { + "cell_type": "code", + "execution_count": 354, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'The coordinate is NOT located within the Traingle'" + ] + }, + "execution_count": 354, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data7=coordinate_traingle(0,0,2,0,2,2,10,10)\n", + "data7.test_location()" + ] + }, + { + "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": 406, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "#linked with Q5\n", + "class points_rectangle(rectangle):\n", + " def __init__(self,x,y,l,w,N=16): \n", + " rectangle.__init__(self,x,y,l,w)\n", + " self.data=[]\n", + " self.N=N \n", + " self.x2=self.x+self.l \n", + " self.y2=self.y\n", + " self.x3=self.x+self.l\n", + " self.y3=self.y+self.w\n", + " self.x4=self.x\n", + " self.y4=self.y+self.w\n", + " \n", + " def generate_data(self):\n", + " ABC=abs((self.x*(self.y2-self.y3)+self.x2*(self.y3-self.y)+self.x3*(self.y-self.y2))/2)\n", + " ACD=abs((self.x*(self.y3-self.y4)+self.x3*(self.y4-self.y)+self.x4*(self.y-self.y3))/2)\n", + " \n", + " while len(self.data)n:\n", + " print (\"The column number should be lower\")\n", + " else:\n", + " self.V=[]\n", + " for i in range(n):\n", + " c=M[i][self.C-1]\n", + " self.V.append(c)\n", + " return self.V\n", + " \n", + " def row_values(self,M):\n", + " self.M=M\n", + " n,m=self.shape(self.M)\n", + " print (\"Enter the row number to dispaly values\")\n", + " self.R=int(input())\n", + " if self.R>m:\n", + " print (\"The column number should be lower\")\n", + " else:\n", + " return M[self.R-1]\n", + " \n", + " def to_list(self,M):\n", + " self.M=M\n", + " n,m=self.shape(self.M)\n", + " M_0=[[0]*m]*n\n", + " #M_1=matrix.matrix_swap(self,self.M,M_0)\n", + " return M_0\n", + " \n", + " \n", + " def block(self,M,n_0,n_1,m_0,m_1):\n", + " self.M=M\n", + " self.n_0=n_0\n", + " self.n_1=n_1\n", + " self.m_0=m_0\n", + " self.m_1=m_1\n", + " n,m=self.shape(self.M)\n", + " \n", + " if self.n_0<0 or self.n_0>n or self.n_1n :\n", + " print (\"Invalid column number\")\n", + " elif self.n_0<0 or self.m_0>m or self.m_1m : \n", + " print (\"Invalid row number\")\n", + " else:\n", + " l=[]\n", + " for i in range(self.n_0-1,self.n_1):\n", + " r=[]\n", + " for j in range(self.m_0-1,self.m_1):\n", + " r.append(M[i][j])\n", + " l.append(r) \n", + " return l\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 266, + "metadata": {}, + "outputs": [], + "source": [ + "mat = matrix_2()" + ] + }, + { + "cell_type": "code", + "execution_count": 267, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(3, 4)" + ] + }, + "execution_count": 267, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M=[[1,2,3,4],[5,6,7,8],[9,10,11,12]]\n", + "mat.shape(M)" + ] + }, + { + "cell_type": "code", + "execution_count": 268, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 5, 9], [2, 6, 10], [3, 7, 11], [4, 8, 12]]" + ] + }, + "execution_count": 268, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "TM=mat.transpose(M)\n", + "TM" + ] + }, + { + "cell_type": "code", + "execution_count": 269, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the column number to display values\n", + "2\n" + ] + }, + { + "data": { + "text/plain": [ + "[5, 6, 7, 8]" + ] + }, + "execution_count": 269, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.column_values(TM)" + ] + }, + { + "cell_type": "code", + "execution_count": 270, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the row number to dispaly values\n", + "2\n" + ] + }, + { + "data": { + "text/plain": [ + "[2, 6, 10]" + ] + }, + "execution_count": 270, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.row_values(TM)" + ] + }, + { + "cell_type": "code", + "execution_count": 271, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]" + ] + }, + "execution_count": 271, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M_1=mat.to_list(M)\n", + "M_1" + ] + }, + { + "cell_type": "code", + "execution_count": 272, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]]" + ] + }, + "execution_count": 272, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M_1=mat.to_list(M)\n", + "M_1" + ] + }, + { + "cell_type": "code", + "execution_count": 273, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 1, 0, 0], [0, 1, 0, 0], [0, 1, 0, 0]]" + ] + }, + "execution_count": 273, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#To prove the new matric M_1 is list of list\n", + "M_1[1][1]=1\n", + "M_1" + ] + }, + { + "cell_type": "code", + "execution_count": 274, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2, 3, 4], [5, 1, 7, 8], [9, 10, 11, 12]]" + ] + }, + "execution_count": 274, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#To test the orginal matrix M is not list of list\n", + "M[1][1]=1\n", + "M" + ] + }, + { + "cell_type": "code", + "execution_count": 275, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2, 3], [5, 1, 7], [9, 10, 11]]" + ] + }, + "execution_count": 275, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.block(M,1,3,1,3)" + ] + }, + { + "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": 276, + "metadata": {}, + "outputs": [], + "source": [ + "def constant(n,m,c):\n", + " return [[float(c)] * m for i in range(n)]\n", + "\n", + "def zeros(n,m):\n", + " return [[0.] * m for i in range(n)]\n", + "\n", + "def ones(n,m):\n", + " return [[1.] * m for i in range(n)]\n", + "\n", + "def eye(n):\n", + " m=zeros(n,n)\n", + " for i in range(n):\n", + " m[i][i]=1\n", + " return m\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 277, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[6.0, 6.0, 6.0, 6.0, 6.0],\n", + " [6.0, 6.0, 6.0, 6.0, 6.0],\n", + " [6.0, 6.0, 6.0, 6.0, 6.0],\n", + " [6.0, 6.0, 6.0, 6.0, 6.0]]" + ] + }, + "execution_count": 277, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "constant(4,5,6)" + ] + }, + { + "cell_type": "code", + "execution_count": 278, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0]]" + ] + }, + "execution_count": 278, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "zeros(4,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 279, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0]]" + ] + }, + "execution_count": 279, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ones(4,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 280, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 1, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 1, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 1, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 1]]" + ] + }, + "execution_count": 280, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "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": 281, + "metadata": {}, + "outputs": [], + "source": [ + "class operation(matrix_2):\n", + " def __init__(self):\n", + " pass\n", + " \n", + " def scalarmul(self,M,c):\n", + " self.M=M\n", + " self.c=c\n", + " n,m=self.shape(self.M)\n", + " R=zeros(n,m)\n", + " for i in range(n):\n", + " for j in range(m):\n", + " R[i][j]=M[i][j]*self.c\n", + " return R\n", + " \n", + " def add(self,M,N):\n", + " self.M=M\n", + " self.N=N\n", + " n1,m1=self.shape(self.M)\n", + " n2,m2=self.shape(self.N)\n", + " R=zeros(n1,m1)\n", + " if (n1,m1)==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " R[i][j]=M[i][j]+N[i][j]\n", + " return R\n", + " else:\n", + " print(\"The matrix shapes has to be same for the summation\")\n", + " \n", + " def sub(self,M,N):\n", + " self.M=M\n", + " self.N=N\n", + " n1,m1=self.shape(self.M)\n", + " n2,m2=self.shape(self.N)\n", + " R=zeros(n1,m1)\n", + " if (n1,m1)==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " R[i][j]=M[i][j]-N[i][j]\n", + " return R\n", + " else:\n", + " print(\"The matrix shapes has to be same for the subtraction\")\n", + " \n", + " def mat_mult(self,M,N):\n", + " self.M=M\n", + " self.N=N\n", + " n1,m1=self.shape(self.M)\n", + " n2,m2=self.shape(self.N)\n", + " R=zeros(n1,m2)\n", + " if (m1)==(n2):\n", + " for i in range(n1):\n", + " for j in range(m2):\n", + " for k in range(m1):\n", + " R[i][j]+=M[i][k]*N[k][j]\n", + " return R\n", + " else:\n", + " print(\"The matrix multiplication is not possible for the given matrix shapes\")\n", + " \n", + " def element_mult(self,M,N):\n", + " self.M=M\n", + " self.N=N\n", + " n1,m1=self.shape(self.M)\n", + " n2,m2=self.shape(self.N)\n", + " R=zeros(n1,m1)\n", + " if (n1,m1)==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " R[i][j]=M[i][j]*N[i][j]\n", + " return R\n", + " else:\n", + " print(\"The matrix shapes has to be same for the emelemt multipication\")\n", + " \n", + " def equals(self,M,N):\n", + " self.M=M\n", + " self.N=N\n", + " n1,m1=self.shape(self.M)\n", + " n2,m2=self.shape(self.N)\n", + " if (n1,m1)==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " if M[i][j]==N[i][j]:\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " print(\"The matrix shapes has to be same for the equal check\")\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 282, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0]]" + ] + }, + "execution_count": 282, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o=operation()\n", + "M=ones(4,4)\n", + "M" + ] + }, + { + "cell_type": "code", + "execution_count": 283, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0]]" + ] + }, + "execution_count": 283, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M1=o.scalarmul(M,4)\n", + "M1" + ] + }, + { + "cell_type": "code", + "execution_count": 284, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 284, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.add(M,M1)" + ] + }, + { + "cell_type": "code", + "execution_count": 285, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0]]" + ] + }, + "execution_count": 285, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.sub(M,M1)" + ] + }, + { + "cell_type": "code", + "execution_count": 286, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0]]" + ] + }, + "execution_count": 286, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.mat_mult(M,M1)" + ] + }, + { + "cell_type": "code", + "execution_count": 287, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0]]" + ] + }, + "execution_count": 287, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.element_mult(M,M1)" + ] + }, + { + "cell_type": "code", + "execution_count": 288, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 288, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "o.equals(M,M1)" + ] + }, + { + "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": 289, + "metadata": {}, + "outputs": [], + "source": [ + "class overload(operation):\n", + " def __init__(self,M):\n", + " self.M=M\n", + " pass\n", + " \n", + " def __add__(self, other):\n", + " return self.add(self.M,other.M)\n", + " \n", + " def __sub__(self, other):\n", + " return self.sub(self.M,other.M)\n", + " \n", + " def __mul__(self, other):\n", + " if isinstance(other,(int,float)):\n", + " return self.scalarmul(self.M,other)\n", + " else:\n", + " return self.mat_mult(self.M,other.M)\n", + " \n", + " def __eq__(self, other):\n", + " return self.equals(self.M,other.M)\n", + " \n", + " def __set__(self, other):\n", + " return matrix.matric_swap(self.M,other.M)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 290, + "metadata": {}, + "outputs": [], + "source": [ + "M = [[1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0]]" + ] + }, + { + "cell_type": "code", + "execution_count": 291, + "metadata": {}, + "outputs": [], + "source": [ + "M1 = [[4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0]]" + ] + }, + { + "cell_type": "code", + "execution_count": 292, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 292, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M+N\n", + "A=overload(M)\n", + "B=overload(M1)\n", + "A+B" + ] + }, + { + "cell_type": "code", + "execution_count": 293, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0]]" + ] + }, + "execution_count": 293, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M-N\n", + "A=overload(M)\n", + "B=overload(M1)\n", + "A-B" + ] + }, + { + "cell_type": "code", + "execution_count": 294, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0],\n", + " [16.0, 16.0, 16.0, 16.0]]" + ] + }, + "execution_count": 294, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M*N\n", + "A=overload(M)\n", + "B=overload(M1)\n", + "A*B" + ] + }, + { + "cell_type": "code", + "execution_count": 296, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0]]" + ] + }, + "execution_count": 296, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M*2\n", + "A=overload(M)\n", + "A*2" + ] + }, + { + "cell_type": "code", + "execution_count": 297, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 297, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M==N\n", + "A=overload(M)\n", + "B=overload(M1)\n", + "A==B" + ] + }, + { + "cell_type": "code", + "execution_count": 298, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 298, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# test M=N\n", + "A=overload(M)\n", + "B=overload(M1)\n", + "A=B\n", + "A==B" + ] + }, + { + "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": 299, + "metadata": {}, + "outputs": [], + "source": [ + "A = [[1,2], [3,4]]" + ] + }, + { + "cell_type": "code", + "execution_count": 300, + "metadata": {}, + "outputs": [], + "source": [ + "B = [[5,6], [7,8]]" + ] + }, + { + "cell_type": "code", + "execution_count": 301, + "metadata": {}, + "outputs": [], + "source": [ + "C = [[9,10], [11,12]]" + ] + }, + { + "cell_type": "code", + "execution_count": 302, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[19.0, 22.0], [43.0, 50.0]]" + ] + }, + "execution_count": 302, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation()\n", + "AB=o.mat_mult(A,B)\n", + "AB" + ] + }, + { + "cell_type": "code", + "execution_count": 303, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[111.0, 122.0], [151.0, 166.0]]" + ] + }, + "execution_count": 303, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation()\n", + "BC=o.mat_mult(B,C)\n", + "BC" + ] + }, + { + "cell_type": "code", + "execution_count": 304, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[31.0, 34.0], [71.0, 78.0]]" + ] + }, + "execution_count": 304, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation()\n", + "AC=o.mat_mult(A,C)\n", + "AC" + ] + }, + { + "cell_type": "code", + "execution_count": 305, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[23.0, 34.0], [31.0, 46.0]]" + ] + }, + "execution_count": 305, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation()\n", + "BA=o.mat_mult(B,A)\n", + "BA" + ] + }, + { + "cell_type": "code", + "execution_count": 306, + "metadata": {}, + "outputs": [], + "source": [ + "#6.1 checking if (AB)C=A(BC)" + ] + }, + { + "cell_type": "code", + "execution_count": 307, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[413.0, 454.0], [937.0, 1030.0]]" + ] + }, + "execution_count": 307, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation() #ABC2 is (AB)C\n", + "ABC1=o.mat_mult(AB,C)\n", + "ABC1 " + ] + }, + { + "cell_type": "code", + "execution_count": 308, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[413.0, 454.0], [937.0, 1030.0]]" + ] + }, + "execution_count": 308, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation() #ABC2 is A(BC)\n", + "ABC2=o.mat_mult(A,BC)\n", + "ABC2 " + ] + }, + { + "cell_type": "code", + "execution_count": 309, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 309, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#checking if (AB)C=A(BC), where ABC1 is (AB)C and ABC2=A(BC) \n", + "o.equals(ABC1,ABC2)" + ] + }, + { + "cell_type": "code", + "execution_count": 310, + "metadata": {}, + "outputs": [], + "source": [ + "#6.2 𝐴(𝐵+𝐶)=𝐴𝐵+𝐴𝐶" + ] + }, + { + "cell_type": "code", + "execution_count": 311, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[14, 16], [18, 20]]" + ] + }, + "execution_count": 311, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation() #BC1 is (B+C)\n", + "BC1=o.add(B,C)\n", + "BC1" + ] + }, + { + "cell_type": "code", + "execution_count": 312, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[50.0, 56.0], [114.0, 128.0]]" + ] + }, + "execution_count": 312, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation() #ABC3 is A(B+C)\n", + "ABC3=o.mat_mult(A,BC1)\n", + "ABC3" + ] + }, + { + "cell_type": "code", + "execution_count": 313, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[50.0, 56.0], [114.0, 128.0]]" + ] + }, + "execution_count": 313, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation() #ABAC is AB+AC\n", + "ABAC=o.add(AB,AC)\n", + "ABAC" + ] + }, + { + "cell_type": "code", + "execution_count": 314, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 314, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test if 𝐴(𝐵+𝐶)=𝐴𝐵+𝐴𝐶\n", + "o.equals(ABC3,ABAC)" + ] + }, + { + "cell_type": "code", + "execution_count": 315, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 315, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#6.3 test if 𝐴𝐵=𝐵𝐴\n", + "o.equals(AB,BA)" + ] + }, + { + "cell_type": "code", + "execution_count": 316, + "metadata": {}, + "outputs": [], + "source": [ + "#6.4 𝐴𝐼=𝐴" + ] + }, + { + "cell_type": "code", + "execution_count": 317, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 0.0], [0.0, 1]]" + ] + }, + "execution_count": 317, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "I=eye(2)\n", + "I" + ] + }, + { + "cell_type": "code", + "execution_count": 318, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 2.0], [3.0, 4.0]]" + ] + }, + "execution_count": 318, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "O=operation()\n", + "AI=o.mat_mult(A,I)\n", + "AI" + ] + }, + { + "cell_type": "code", + "execution_count": 319, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 319, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test if 𝐴𝐼=𝐴\n", + "o.equals(AI,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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/Labs/Lab-7/Lab-7-solution-nabin.ipynb b/Labs/Lab-7/Lab-7-solution-nabin.ipynb new file mode 100644 index 0000000..2ac1045 --- /dev/null +++ b/Labs/Lab-7/Lab-7-solution-nabin.ipynb @@ -0,0 +1,6330 @@ +{ + "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": 1, + "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": 2, + "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 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": 3, + "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": 4, + "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", + " # 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_summary(self,a_grader):\n", + " for k,a_student in self.__students.items():\n", + " a_student.add_grade(a_grader.apply(a_student))\n", + " \n", + " def apply_grader(self,a_grader,grade_name):\n", + " for k,a_student in self.__students.items():\n", + " a_student.add_grade(a_grader.apply(a_student[grade_name]))\n", + " \n", + " def apply_calculator(self,a_calculator,**kwargs):\n", + " a_calculator.apply(self,**kwargs)\n", + " \n", + " # Accessors\n", + " def data(self):\n", + " return self.__data\n", + "\n", + " def students(self):\n", + " return self.__students\n", + " \n", + " \n", + " def get_data(self,key=None):\n", + " a_data=dict()\n", + " for k,v in self.__data.items():\n", + " if key:\n", + " if key in k:\n", + " a_data[k]=v\n", + " else:\n", + " a_data[k]=v\n", + "\n", + " return a_data \n", + " \n", + " # Print functions\n", + " def print_data(self):\n", + " for k,v in self.__data.items():\n", + " print (k,\":\",v)\n", + " \n", + " def print_grades(self,grade_name):\n", + " if isinstance(grade_name,str):\n", + " grade_names=list()\n", + " grade_names.append(grade_name)\n", + " else:\n", + " grade_names=grade_name\n", + " \n", + " for k,a_student in self.__students.items():\n", + " print (a_student.name(),end=\"\")\n", + " for a_grade_name in grade_names:\n", + " print (a_student[a_grade_name],end=\"\")\n", + " print()\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", + " def print_Mean_STD(self,a_grade_book,grade_name): \n", + " print(\"Mean of \"+grade_name,a_grade_book[grade_name+\" Mean\"])\n", + " print(\"STD of \"+grade_name,a_grade_book[grade_name+\" STD\"])\n", + " #print(\"Max of \"+grade_name,a_grade_book[grade_name+\" Max\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "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", + " super().__init__(\"Uncurved Percent Based Grade Calculator \"+self.__grade_name+\" Max=\"+str(self.__max_grade))\n", + " #calculator.__init__(self,\"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": 6, + "metadata": {}, + "outputs": [], + "source": [ + "class calculator(alg): \n", + " def __init__(self,name):\n", + " super().__init__(name)\n", + "\n", + " def apply(self,a_grade_book):\n", + " raise NotImplementedError\n", + "class mean_std_calculator(calculator):\n", + " def __init__(self):\n", + " super().__init__(\"Mean and Standard Deviation Calculator\")\n", + " \n", + " \n", + " def apply(self,a_grade_book,grade_name,**kwargs):\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", + " # a_grade_book[grade_name+\" Max\"] = np.maximum(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": 7, + "metadata": {}, + "outputs": [], + "source": [ + "def csv_reader(filename):\n", + " f=open(filename,\"r\")\n", + " first_line = f.readline().rstrip()\n", + " fields=first_line.split(\",\")\n", + "\n", + " data=list()\n", + "\n", + " line = f.readline().rstrip()\n", + " while line:\n", + " items=line.split(\",\")\n", + " \n", + " row=list()\n", + " for item in items:\n", + " try:\n", + " d=float(item)\n", + " except ValueError:\n", + " d=item\n", + " row.append(d)\n", + " \n", + " data.append(row)\n", + " \n", + " line = f.readline().rstrip()\n", + "\n", + " f.close()\n", + " book=list()\n", + " for i in range(len(data)):\n", + " book.append(dict(zip(fields,data[i])))\n", + " return book" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [], + "source": [ + "d=csv_reader(\"Data1401-Grades.csv\")\n", + "#print(d)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.0\n" + ] + } + ], + "source": [ + "print(d[5][\"l3_5\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 0.0\n", + "1 0.0\n", + "2 7.0\n", + "3 5.0\n", + "4 0.0\n", + "5 10.0\n", + "6 10.0\n", + "7 0.0\n", + "8 0.0\n", + "9 0.0\n", + "10 7.0\n", + "11 8.0\n", + "12 7.0\n", + "13 10.0\n", + "14 10.0\n", + "15 0.0\n" + ] + } + ], + "source": [ + "for i,v in enumerate(d):\n", + " #print(i,v)\n", + " print (i,v[\"l3_5\"])" + ] + }, + { + "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": "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": 11, + "metadata": {}, + "outputs": [], + "source": [ + "class_data=csv_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,v in enumerate(class_data[0].keys()):\n", + " a_student_0.add_grade(grade(v,value=class_data[student_i][v]))\n", + " \n", + " a_grade_book.add_student(a_student_0)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Datal3_5: 0\n", + "Student 1 Student Datal3_5: 0\n", + "Student 2 Student Datal3_5: 7.0\n", + "Student 3 Student Datal3_5: 5.0\n", + "Student 4 Student Datal3_5: 0\n", + "Student 5 Student Datal3_5: 10.0\n", + "Student 6 Student Datal3_5: 10.0\n", + "Student 7 Student Datal3_5: 0\n", + "Student 8 Student Datal3_5: 0\n", + "Student 9 Student Datal3_5: 0\n", + "Student 10 Student Datal3_5: 7.0\n", + "Student 11 Student Datal3_5: 8.0\n", + "Student 12 Student Datal3_5: 7.0\n", + "Student 13 Student Datal3_5: 10.0\n", + "Student 14 Student Datal3_5: 10.0\n", + "Student 15 Student Datal3_5: 0\n" + ] + } + ], + "source": [ + "a_grade_book.print_grades(\"l3_5\")" + ] + }, + { + "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": 14, + "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", + " super().__init__(name)\n", + "\n", + " def apply(self,a_student):\n", + " raise NotImplementedError\n", + " \n", + "class grade_summer(summary_calculator):\n", + " def __init__(self,prefix,n):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " super().__init__(\"Sum_Grades\")\n", + " \n", + " def apply(self,a_student):\n", + " labels=[self.__prefix+str(x) for x in range(1,self.__n+1)]\n", + " \n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", + " return grade(self.__prefix+\"sum\",value=grade_sum)\n", + "\n", + "class grade_overall(summary_calculator):\n", + " def __init__(self,data):\n", + " self.__data=data\n", + " super().__init__(\"Overall_Grades\")\n", + " \n", + " def apply(self,a_student):\n", + " fields = self.__data[0].keys()\n", + " labels = list()\n", + " for i in fields:\n", + " labels.append(i)\n", + " \n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", + " return grade(\"Overall_Grades\",value=grade_sum) " + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l2_\",7))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l3_\",14))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l4_\",11))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"q1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"e1_\",15))" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_overall(class_data))" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"Overall_Grades\",max_grade=490))" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 35.0\n", + "Overall_Grades: 170.5\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum: 0\n", + "Overall_Grades: 59.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 20.0\n", + "Overall_Grades: 155.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 115.0\n", + "Overall_Grades: 423.0\n", + "Overall_Grades Letter: B\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 24.0\n", + "Overall_Grades: 236.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 95.0\n", + "Overall_Grades: 356.5\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 37.0\n", + "Overall_Grades: 255.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 77.0\n", + "Overall_Grades: 306.0\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Overall_Grades: 319.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 117.0\n", + "Overall_Grades: 298.5\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 138.0\n", + "Overall_Grades: 475.0\n", + "Overall_Grades Letter: A\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 110.0\n", + "Overall_Grades: 396.0\n", + "Overall_Grades Letter: B-\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 104.0\n", + "Overall_Grades: 352.0\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 111.0\n", + "Overall_Grades: 359.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Overall_Grades: 325.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 134.0\n", + "Overall_Grades: 420.5\n", + "Overall_Grades Letter: B\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.print_students()" + ] + }, + { + "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": 24, + "metadata": {}, + "outputs": [], + "source": [ + "# Lab 1\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"l1_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l2_sum 51.09375\n", + "STD of l2_sum 21.05663401252679\n" + ] + } + ], + "source": [ + "# Lab 2\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"l2_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"l2_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l3_sum 73.3125\n", + "STD of l3_sum 38.301792957379945\n" + ] + } + ], + "source": [ + "# Lab 3\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"l3_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"l3_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l4_sum 34.125\n", + "STD of l4_sum 30.421774685248064\n" + ] + } + ], + "source": [ + "# Lab 3\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"l4_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"l4_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of q1_sum 6.40625\n", + "STD of q1_sum 4.469405546322688\n" + ] + } + ], + "source": [ + "# Quiz 1\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"q1_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"q1_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of e1_sum 82.6875\n", + "STD of e1_sum 42.937045121316864\n" + ] + } + ], + "source": [ + "# Exam 1\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"e1_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"e1_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of Overall_Grades 306.625\n", + "STD of Overall_Grades 106.41509232716946\n" + ] + } + ], + "source": [ + "# Overall Semester\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"Overall_Grades\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"Overall_Grades\")" + ] + }, + { + "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": 31, + "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,overwrite=False,**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", + " 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", + " \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", + " a_student.add_grade(grade(self.__grade_name,value=self.__grades_definition[i][1]),\n", + " overwrite = overwrite) \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "C:\\Users\\Basnet-home\\Anaconda3\\lib\\site-packages\\ipykernel_launcher.py:50: RuntimeWarning: invalid value encountered in double_scalars\n" + ] + } + ], + "source": [ + "# Lab 1\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l1_sum\",a_grade_book[\"l1_sum Mean\"],a_grade_book[\"l1_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [], + "source": [ + "# Lab 2\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l2_sum\",a_grade_book[\"l2_sum Mean\"],a_grade_book[\"l2_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [], + "source": [ + "# Lab 3\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l3_sum\",a_grade_book[\"l3_sum Mean\"],a_grade_book[\"l3_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [], + "source": [ + "# Lab 4\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l4_sum\",a_grade_book[\"l4_sum Mean\"],a_grade_book[\"l4_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [], + "source": [ + "# Quix 1\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"q1_sum\",a_grade_book[\"q1_sum Mean\"],a_grade_book[\"q1_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [], + "source": [ + "# Exam 1\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"e1_sum\",a_grade_book[\"e1_sum Mean\"],a_grade_book[\"e1_sum STD\"]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B\n", + "l3_sum: C\n", + "l4_sum: C+\n", + "q1_sum: B\n", + "e1_sum: C+\n", + "Overall_Grades: 170.5\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: F\n", + "l3_sum: C-\n", + "l4_sum: C+\n", + "q1_sum: C\n", + "e1_sum: C-\n", + "Overall_Grades: 59.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: F\n", + "l3_sum: C+\n", + "l4_sum: C+\n", + "q1_sum: C\n", + "e1_sum: C\n", + "Overall_Grades: 155.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B\n", + "l3_sum: B+\n", + "l4_sum: A\n", + "q1_sum: B+\n", + "e1_sum: B+\n", + "Overall_Grades: 423.0\n", + "Overall_Grades Letter: B\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: C+\n", + "l3_sum: B-\n", + "l4_sum: C+\n", + "q1_sum: C\n", + "e1_sum: C\n", + "Overall_Grades: 236.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B+\n", + "l3_sum: B\n", + "l4_sum: B-\n", + "q1_sum: B\n", + "e1_sum: B-\n", + "Overall_Grades: 356.5\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B-\n", + "l3_sum: C+\n", + "l4_sum: C+\n", + "q1_sum: B+\n", + "e1_sum: C+\n", + "Overall_Grades: 255.0\n", + "Overall_Grades Letter: F-\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B+\n", + "l3_sum: C-\n", + "l4_sum: B\n", + "q1_sum: B+\n", + "e1_sum: C+\n", + "Overall_Grades: 306.0\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: C\n", + "l3_sum: C-\n", + "l4_sum: A-\n", + "q1_sum: B\n", + "e1_sum: B\n", + "Overall_Grades: 319.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B\n", + "l3_sum: C+\n", + "l4_sum: C+\n", + "q1_sum: B\n", + "e1_sum: B+\n", + "Overall_Grades: 298.5\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: C+\n", + "l3_sum: A\n", + "l4_sum: A+\n", + "q1_sum: C\n", + "e1_sum: A-\n", + "Overall_Grades: 475.0\n", + "Overall_Grades Letter: A\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B+\n", + "l3_sum: B\n", + "l4_sum: B\n", + "q1_sum: B+\n", + "e1_sum: B\n", + "Overall_Grades: 396.0\n", + "Overall_Grades Letter: B-\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B\n", + "l3_sum: A-\n", + "l4_sum: C+\n", + "q1_sum: B+\n", + "e1_sum: B\n", + "Overall_Grades: 352.0\n", + "Overall_Grades Letter: C-\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: C+\n", + "l3_sum: A-\n", + "l4_sum: C+\n", + "q1_sum: C\n", + "e1_sum: B\n", + "Overall_Grades: 359.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B+\n", + "l3_sum: B\n", + "l4_sum: C+\n", + "q1_sum: C\n", + "e1_sum: B\n", + "Overall_Grades: 325.0\n", + "Overall_Grades Letter: C\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: F-\n", + "l2_sum: B\n", + "l3_sum: B+\n", + "l4_sum: B\n", + "q1_sum: B\n", + "e1_sum: A-\n", + "Overall_Grades: 420.5\n", + "Overall_Grades Letter: B\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "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": 39, + "metadata": {}, + "outputs": [], + "source": [ + "# Your solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [], + "source": [ + "class calculator_drop_lower_grades(alg): \n", + " def __init__(self,name):\n", + " super().__init__(name)\n", + "\n", + " def apply(self,a_student):\n", + " raise NotImplementedError\n", + " \n", + "class grade_summer_drop_lower_grades(calculator_drop_lower_grades):\n", + " def __init__(self,prefix,n,drop):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " self.__drop=drop\n", + " super().__init__(\"New_Dropped_Grades\")\n", + " \n", + " def apply(self,a_student):\n", + " labels=[self.__prefix+str(x) for x in range(1,self.__n+1)]\n", + " \n", + " grades=list()\n", + " for label in labels:\n", + " grades.append(a_student[label].value())\n", + " grade_sorted = sorted(grades)[::-1]\n", + " grade_sum=0.\n", + " for i in range(len(grade_sorted)-self.__drop-1):\n", + " grade_sum+=grade_sorted[i]\n", + " return grade(self.__prefix+\"New_Dropped_Grades\",value=(grade_sum)) " + ] + }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 35.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum: 0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 0\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 20.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 0\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 115.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 24.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 95.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 37.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 77.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 39.5\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 117.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 138.0\n", + "Final Grade Letter: A+\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 110.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 104.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 111.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Final Grade Letter: A\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 134.0\n", + "Final Grade Letter: A+\n", + "l2_New_Dropped_Grades: 40.0\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.apply_summary(grade_summer_drop_lower_grades(\"l2_\",7,2))\n", + "\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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": 42, + "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": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [], + "source": [ + "class calculator_final(alg): \n", + " def __init__(self,name):\n", + " super().__init__(name)\n", + "\n", + " def apply(self,a_student):\n", + " raise NotImplementedError\n", + "class weighted_grade(calculator_final):\n", + " __grades_definition=[ (12,\"A+\"),\n", + " (11,\"A\"),\n", + " (10,\"A-\"),\n", + " (9,\"B+\"),\n", + " (8,\"B\"),\n", + " (7,\"B-\"),\n", + " (6,\"C+\"),\n", + " (5,\"C\"),\n", + " (4,\"C-\"),\n", + " (3,\"D+\"),\n", + " (2,\"D\"),\n", + " (1,\"D-\"),\n", + " (0,\"F\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,lab_grade_name_1,lab_grade_name_2,lab_grade_name_3,lab_grade_name_4,grade_name_2,grade_name_3,grade_name_4):\n", + " \n", + " self.__lab_grade_name_1=lab_grade_name_1\n", + " self.__lab_grade_name_2=lab_grade_name_2\n", + " self.__lab_grade_name_3=lab_grade_name_3\n", + " self.__lab_grade_name_4=lab_grade_name_4\n", + " self.__grade_name_2=grade_name_2\n", + " self.__grade_name_3=grade_name_3\n", + " self.__grade_name_4=grade_name_4\n", + " super().__init__(\"Weighted Averaged Grade Calculator \"+self.__grade_name+\" Max=\"+str(self.__max_grade))\n", + " \n", + " def apply(self,a_grade_book,**kwargs):\n", + " \n", + " for k,a_student in a_grade_book.get_students().items():\n", + " lab_grade_1=a_student[self.__lab_grade_name_1]\n", + " lab_grade_2=a_student[self.__lab_grade_name_2]\n", + " lab_grade_3=a_student[self.__lab_grade_name_3]\n", + " lab_grade_4=a_student[self.__lab_grade_name_4]\n", + " a_grade_2=a_student[self.__grade_name_2]\n", + " a_grade_3=a_student[self.__grade_name_3]\n", + " a_grade_4=a_student[self.__grade_name_4]\n", + "\n", + "\n", + " a_grade_1 = ((10*lab_grade_1.value())+lab_grade_2.value()+lab_grade_3.value()+lab_grade_4.value())/4.\n", + " \n", + " lab_percent=a_grade_1/self.__max_grade\n", + " quiz_percent=(10*a_grade_2.value())/self.__max_grade\n", + " mid_percent=a_grade_3.value()/self.__max_grade\n", + " final_percent=a_grade_4.value()/self.__max_grade\n", + " \n", + " percent = lab_percent*0.5+quiz_percent*0.1+mid_percent*0.2+final_percent*0.2\n", + " \n", + " for i,v in enumerate(self.__grades_definition):\n", + " percent = percent*v[0]\n", + " if percent>=v[0]:\n", + " break\n", + " \n", + " a_student.add_grade(grade(\"Final Grade\"+\" Letter\",value=self.__grades_definition[i][1]))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [], + "source": [ + "# new final gradebook\n", + "grade_data = csv_reader(\"Data1401-Grades.csv\")\n", + "a_grade_book=grade_book(\"Final Dala 1401 Grade\")\n", + "\n", + "for student_i in range(len(grade_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + " \n", + " for k,v in enumerate(grade_data[0].keys()):\n", + " a_student_0.add_grade(grade(v,value=grade_data[student_i][v]))\n", + "\n", + " a_grade_book.add_student(a_student_0)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l2_\",7))" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l3_\",14))" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l4_\",11))" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"q1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 50, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"e1_\",15))" + ] + }, + { + "cell_type": "code", + "execution_count": 51, + "metadata": {}, + "outputs": [], + "source": [ + "# Assuming mid-term grade = final grade for each student\n", + "a_grade_book.apply_calculator(weighted_grade(\"l1_sum\",\"l2_sum\",\"l3_sum\",\"l4_sum\",\"q1_sum\",\"e1_sum\",\"e1_sum\"),overwrite=False)" + ] + }, + { + "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": 52, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 Student 0 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 35.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "1 Student 1 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "l1_sum: 10.0\n", + "l2_sum: 0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "q1_sum: 0\n", + "e1_sum: 0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "2 Student 2 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 20.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "3 Student 3 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 115.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "4 Student 4 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 24.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "5 Student 5 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 95.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "6 Student 6 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 37.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "7 Student 7 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 77.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "8 Student 8 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 117.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "10 Student 10 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 138.0\n", + "Final Grade Letter: A+\n", + "_______________________________________\n", + "11 Student 11 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 110.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "12 Student 12 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 104.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "13 Student 13 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 111.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "14 Student 14 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 103.0\n", + "Final Grade Letter: A\n", + "_______________________________________\n", + "15 Student 15 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_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", + "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: 134.0\n", + "Final Grade Letter: A+\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "# Your solution here\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "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.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}