From a5d86618728a35c9b161b64fffb619642e99be92 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 7 Feb 2020 14:40:35 -0600 Subject: [PATCH 01/12] Add files via upload --- Labs/Lab-2/Copy_of_Lab_1.ipynb | 1490 ++++++++++++++++++++++++++++++++ 1 file changed, 1490 insertions(+) create mode 100644 Labs/Lab-2/Copy_of_Lab_1.ipynb diff --git a/Labs/Lab-2/Copy_of_Lab_1.ipynb b/Labs/Lab-2/Copy_of_Lab_1.ipynb new file mode 100644 index 0000000..277631b --- /dev/null +++ b/Labs/Lab-2/Copy_of_Lab_1.ipynb @@ -0,0 +1,1490 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-1.ipynb", + "provenance": [], + "collapsed_sections": [], + "toc_visible": true + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "O5vg8KKRq0sy", + "colab_type": "text" + }, + "source": [ + "# Lab 1\n", + "\n", + "## Python Notebooks on Google Colab\n", + "\n", + "Data 1401's Labs, Homework, and Exams will be all in form of iPython notebooks. You may already be familiar with python notebooks if you have used Jupyter before, for example in Data 1301. If so, you are welcome to use whatever means you have to run Jupyter notebooks for this course, though you may get limited support. Our primary means of running python notebooks will be through [Google Colab](https://colab.research.google.com) and we will be storing files on google drive.\n", + "\n", + "You will need a google account. If you do not have one or you wish to use a different account for this course, please follow [these instructions](https://edu.gcfglobal.org/en/googledriveanddocs/getting-started-with-google-drive/1/) to make an account.\n", + "\n", + "Once you are ready with your account, you can continue in Colab. Click on the following badge to open this notebook in Colab:\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-1/Lab-1.ipynb)\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "guur-Rduodta", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FVt_1hPt1dAK", + "colab_type": "text" + }, + "source": [ + "## Notebooks in Colab\n", + "\n", + "You now are presumably in Colab. Word of caution, by default, Google Colab does not save your notebooks, so if you close your session, you will loose your work.\n", + "\n", + "So first thing: from the file menu above select \"Save a copy in Drive\"." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x0JBL_RFrDDj", + "colab_type": "text" + }, + "source": [ + "## Storing Notebooks in Google Drive\n", + "A better way to work is to save your notebooks directly into Google Drive and upload directly to Git (where you will be downloading and uploading your homework). In order properly setup Git, we'll need to work more directly in your Google Drive.\n", + "\n", + "On the left sidebar, press the file icon to see a listing of files accessibile to this Notebook. Then press \"Mount Drive\" and follow the instructions to mount your Google Drive in this notebook. A new cell will be inserted into this notebook, which after you run by pressing the play button will instruct you to follow a link to log into your Google Account and enable access to your Drive in another tab. Finally you will copy a link from the new tab back into the cell in this notebook. Once you are done, press refresh under files in the left sidebar and you should have \"drive/My Drive\" appear." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hwJ6wJk3tiLv", + "colab_type": "text" + }, + "source": [ + "## Github\n", + "All the class material will be stored on github. You will also submit your homework using github. To do so, you will need a github account.\n", + "\n", + "If you do not already have a github account or wish to create a new one for this course, create one:\n", + "* Browse to [github.com](https://github.com).\n", + "* Click the green “Sign up for GitHub”\tbutton.\n", + "* Follow instructions for creating an account.\n", + "* Make sure you remember your github username and password.\n", + "\n", + "Write an email to the course TA titled \"Data 1401: Github account\" with your github username (not your password) as the contents.\n", + "\n", + "## Google Groups\n", + "\n", + "Class annoucements will be made via google groups. If you did not already receive an invite to the class google group, had trouble with the invite, or wish to use a different email address, write an email to the course TA titled \"Data 1401: Google Group\" with your preferred email.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TjfIzdQZqvzk", + "colab_type": "text" + }, + "source": [ + "## Introduction: Unix, Git, and Jupyter\n", + "\n", + "This lab aims to introduce you to basic Unix, familiarize you with iPython notebooks and get you setup to submit your homework.\n", + "*italicized text*" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C_LmOgzFqvzp", + "colab_type": "text" + }, + "source": [ + "\n", + "\n", + "### Terminal, Shell, and ssh\n", + "\n", + "\n", + "The terminal is a simple program that generally runs another program, taking mostly keyboard input from you, passing it to this other program, and taking the output of the program and displaying on the screen for you.\n", + "\n", + "The terminal usually runs a program called a shell. Shells present a command prompt where you can type in commands, which are then executed when you press enter. In most shells, there are some special commands which the shell will execute. Everything else you type in, the shell will assume is a name of a program you want to run and arguments you want to pass that program. So if the shell doesn't recognize something you type in, it'll try to find a program with a name that is the same as the first word you gave it. \n", + "\n", + "### Shell in Colab\n", + "\n", + "Unfortunately, google Colab does not allow you to open a terminal window. Jupyter does, so if you are running in Jupyter (which most of you will not be), you may choose to open a terminal window by returning to the jupyter file list tab and selecting new terminal from the top right.\n", + "\n", + "For Colab, we will have to do something non-ideal, but functional. There are several ways to execute shell commands from within a python notebook. For example, you can use any shell command by putting \"!\" in front of the command:\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "KJ5f-WO0wcAv", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 106 + }, + "outputId": "fa03c8bc-9edc-4239-c987-fbdb4a495b3a" + }, + "source": [ + "!ls\n", + "!echo \"----------\"\n", + "!ls sample_data" + ], + "execution_count": 1, + "outputs": [ + { + "output_type": "stream", + "text": [ + "sample_data\n", + "----------\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "8f-n4AXFw-dD", + "colab_type": "text" + }, + "source": [ + "Unfortunately, every time you use \"!\" a new environment is created and the state reverted to the original state. Try to understand the difference between the following two sets of commands:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "99nrBYTWxZJr", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 71 + }, + "outputId": "93bd66ee-8b16-41f4-82ec-ff3a0ef859af" + }, + "source": [ + "!echo \"Technique 1:\"\n", + "!ls\n", + "!cd sample_data\n", + "!ls" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 1:\n", + "sample_data\n", + "sample_data\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2-Znf97Lxl-Z", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 106 + }, + "outputId": "c583a8a8-3ddb-425a-cb4b-fbea5ea61226" + }, + "source": [ + "!echo \"Technique 2:\"\n", + "!ls ; cd sample_data ;ls" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 2:\n", + "sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "4x9n1rAkxyYl", + "colab_type": "text" + }, + "source": [ + "Notebooks allow a bit of \"magic\" (using \"%\") to avoid some of these limitations:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vLBPTX4rx3gd", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 124 + }, + "outputId": "04476fc8-9ce6-4023-daa0-dc82926f434b" + }, + "source": [ + "!echo \"Technique 3:\"\n", + "!ls \n", + "%cd sample_data \n", + "!ls" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Technique 3:\n", + "sample_data\n", + "/content/sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "a0V_wt5uQwvQ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "U8XpvPjcyH0w", + "colab_type": "text" + }, + "source": [ + "For our purposes, we are just going to explicitly start a new shell and interact with it in the output cell. Execute the following cell. You will be able to type and execute commands. Look around a bit using \"ls\" and \"cd. You can stop the cell from running by typing \"exit\"." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q-4hfZBywW25", + "colab_type": "text" + }, + "source": [ + "While in this instance your shell is running in a this notebook, you can also run terminals natively on your own computer. On Linux or MacOS, you just have to run a program called terminal. In Windows you can start a \"command prompt\". \n", + "\n", + "\n", + "Type in \"ls\" into the terminal and press enter. The shell will find a program called \"ls\", a standard tool in Unix, and run it. \"ls\" lists the contents (files and directories) of your current directory. If you are just starting in this course, you probably only see the git repository you cloned. \n", + "\n", + "A subtle point to realize here is that while the terminal is running in the browser that is running on the computer in front of you, the shell is actually running on a machine on google hardware. The shell prompt typically displays the name of the machine you are using. What you are not seeing is that there is an intermidate program between the terminal running on your computer and the shell running on google. This intermidary program is taking your input from the terminal sending it over the network to google and bringing back the responses for you terminal to display.\n", + "\n", + "A bit of extra information. If you start a terminal on your own computer, the shell runs locally. The \"ls\" command would then list contents of a directory on your computer. You can typically connect to Unix computers by evoking a shell running on that machine over the network. In this case, you would have to initiate this intermidiary program yourself. The program is called \"ssh\" (secure shell). You can \"ssh\" to another machine from your machine, by simply typing \"ssh\" followed by the machine name or IP address. Most likely you would be prompted for a password, after which you would dropped into the prompt of a shell running on the remote machine. \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "51Eya4LBqvzs", + "colab_type": "text" + }, + "source": [ + "## Programs and Environment Variables\n", + "\n", + "You have a listing of your current directory, but you don't know where that directory resides. You can see what directory you are using the command \"pwd\" (print working directory). Issue the command and look at the response. You'll get a slash (\"/\") separated list, known as the path, of the directory hierarchy of your current working directory. On Colab, this will start with \"contents\"\n", + "\n", + "Now back to thinking about the command prompt. Since \"ls\" is a program, it most be stored somewhere. It is clearly not in your working directory, because you didn't see it when you executed \"ls\". We can ask the shell to tell us where it found \"ls\" using the \"which ls\" command. Note that \"which\" is also a program. \"which ls\" comes back with \"/bin/ls\", telling you the \"ls\" program is sitting in \"/bin\" directory of the system. \n", + "\n", + "Lets see what else is in there by issuing a \"ls /bin\" command. You will get a long list of programs. You can run any of these programs by just typing their names and pressing enter. You may be able to guess what some of these programs do, but if you want to know, most of them provide you help, using \"--help\" or \"-h\" flag. For example execute \"ls --help\". For more information about a program or command, you can use Unix's manual pages using the \"man\" command. Try typing \"man ls\". Note that you will need to press space to scroll through lengthy manual pages and \"q\" to exit back to the shell prompt. \n", + "\n", + "Another command interesting is \"echo\". \"echo\" simply prints whatever you put after it to the screen. Try executing \"echo Hello World.\"\n", + "\n", + "At this point, you may wonder how was it that the shell knew to look for programs in \"/bin\"? The shell keeps a list of places to look for programs an environment variable with the name \"PATH\". The shell keeps a table that map string variable names to string expressions. When the shell starts, its configuration files set some environment variables that it uses. You can see the full list of defined environment variables using the command \"printenv\".\n", + "\n", + "You can use a environment variable in a shell by prepending name of the variable with a dollar sign character (\"\\$\"). So you can print out the PATH environment variable using the command \"echo $PATH\". What you will see is a colon (\":\") separated list of directories that the shell will search (in order) whenever you type in anything.\n", + "\n", + "You can set you own environment variables. Different shells have different syntax. Lets first figure out what shell we are running. \n", + "\n", + "*Exercise 1:* Use the \"echo\" command to print out the value of the \"SHELL\" environment variable:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5soC4JWQJ9G2", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + }, + "outputId": "3adab65f-fe50-4774-d61a-7b68ba8780a9" + }, + "source": [ + "!echo $SHELL" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/bin/bash\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YS7YFiPwqvzu", + "colab_type": "text" + }, + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YoEgruUhqvzw", + "colab_type": "text" + }, + "source": [ + "## Navigating Directories\n", + "\n", + "You can change your current directory using the \"cd\" shell command. Note that \"cd\" is not a Unix program. Once in a directory, you can use the \"ls\" command to list the contents or \"pwd\" to remind yourself your current working directory. You can move back one level in your current directory hierarchy using \"cd ..\". In general \"..\" represents the path to a directory one level above your current directory, \"../..\" represents two levels up, and so on. \".\" represents the current directory. If you look at the PATH environment variable, you'll notice that the last item is \".\", telling the shell to look into your current directory for commands. Finally the \"~\" character always refers to your home directory.\n", + "\n", + "Some other file manipulation commands:\n", + "\n", + " - The \"mkdir\" command creates new directories. \n", + " - \"cp\" and \"mv\" allow you to copy and move (or rename) files, taking 2 arguments: the original path/filename and the target path/filename. \n", + " - The \"rm\" and \"rmdir\" commands remove (delete) files and directories.\n", + "\n", + "\n", + "*Exercise 2:* Using the \"cd\" command, navigate into \"drive/My\\ Drive\" directory. Create a new directory called \"Data-1441\", and another directory inside \"Data-1441\" called \"Lab-1-Solutions\". Perform the rest of the lab in this directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gSTrLpwcSLGr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "jZgVG-6hSEdL", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 126 + }, + "outputId": "bd66f690-cef5-43d1-97e1-f1a1c04e6177" + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 19, + "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": { + "id": "nzqj2-ahKPWl", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "29c58201-02a3-4712-ec13-2dbf6d17d112" + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (123): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@4a3f943c3636: /content/sample_data\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ls\n", + "\u001b[0m\u001b[01;32manscombe.json\u001b[0m \u001b[01;34mData-1441\u001b[0m mnist_train_small.csv\n", + "california_housing_test.csv favorite-colors-list.txt \u001b[01;32mREADME.md\u001b[0m\n", + "california_housing_train.csv mnist_test.csv\n", + "\u001b]0;root@4a3f943c3636: /content/sample_data\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n", + "\u001b]0;root@4a3f943c3636: /content/drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34m'My Drive'\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd My\\Drive\n", + "bash: cd: MyDrive: No such file or directory\n", + "\u001b]0;root@4a3f943c3636: /content/drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34m'My Drive'\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd /My\\ Drive\n", + "bash: cd: /My Drive: No such file or directory\n", + "\u001b]0;root@4a3f943c3636: /content/drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive/My\\ Drive\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# mkdir Data-1441\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# ls\n", + " 010-CV_BRTC-Arif-2017.docx\n", + " \u001b[0m\u001b[01;35m20170317_112443.jpg\u001b[0m\n", + " \u001b[01;35m20180221_110637.jpg\u001b[0m\n", + " 6-15_math-bangla.pdf\n", + "'Application Form.pdf'\n", + " \u001b[01;34mApplication_USA\u001b[0m\n", + "\u001b[01;34m'Arif-M.Sc Presentation'\u001b[0m\n", + "'Arif_Pad (1).docx'\n", + " Arif_Pad.docx\n", + "\u001b[01;34m'Auto Call Recorder'\u001b[0m\n", + "'BD map.gmap'\n", + " \u001b[01;34mBirthday_Aishy\u001b[0m\n", + " \u001b[01;34mBRTC_Secretary\u001b[0m\n", + " \u001b[01;35mBUET.png\u001b[0m\n", + " \u001b[01;34mBUGS_Secretary\u001b[0m\n", + "\u001b[01;34m'Car Ownership Transfer'\u001b[0m\n", + "\u001b[01;34m'Colab Notebooks'\u001b[0m\n", + " \u001b[01;34mConvener\u001b[0m\n", + "'CV_Academic_ Arif.pdf'\n", + " CV_BRTC-Arif.doc\n", + " \u001b[01;34mData-1441\u001b[0m\n", + " \u001b[01;34mDelft3D_manuals\u001b[0m\n", + " document.pdf\n", + " \u001b[01;35mdr-ferdousi-islam-lipi_70_1.jpg\u001b[0m\n", + "\u001b[01;34m'Duncan Brothers Ltd'\u001b[0m\n", + "\u001b[01;34m'Earthquake Assignment'\u001b[0m\n", + " \u001b[01;34mEbook\u001b[0m\n", + " \u001b[01;34mE_Flow_Gorai\u001b[0m\n", + "\u001b[01;34m'Ehsan Vai'\u001b[0m\n", + " \u001b[01;34mEnglish_Learning\u001b[0m\n", + " excel.pdf\n", + " ex_routine_final.pdf\n", + " Final_List_of_Group_A_House_05.02.2017.xls\n", + " Flow_Duration_Tutorial_DL_File.xls\n", + " folder-lock-en.exe\n", + "\u001b[01;34m'For Sheola Hydrology expert'\u001b[0m\n", + "\u001b[01;34m'From Dropbox'\u001b[0m\n", + " \u001b[01;34mGeoSWMM\u001b[0m\n", + " \u001b[01;34mGIS\u001b[0m\n", + "\u001b[01;34m'Google Photos'\u001b[0m\n", + "\u001b[01;34m'GPS Data Extraction'\u001b[0m\n", + " Grade_Sheet_Preparation.xlsx\n", + " \u001b[01;34mGRE_Triumph\u001b[0m\n", + " \u001b[01;34mHEC-Soft\u001b[0m\n", + " \u001b[01;34mHEQEP\u001b[0m\n", + " house_allotment_A.pdf\n", + "'Invitation List for Marriage Ceremony.docx'\n", + " Item_Nuffic_PnD.docx\n", + "\u001b[01;34m'January 15 Term'\u001b[0m\n", + "\u001b[01;34m'January 16 Term'\u001b[0m\n", + "\u001b[01;34m'January 17 Term'\u001b[0m\n", + "\u001b[01;34m'January 18 Term'\u001b[0m\n", + " \u001b[01;34mJFCL\u001b[0m\n", + " \u001b[01;34mJFCL_Visit\u001b[0m\n", + "\u001b[01;34m'July 14 Term'\u001b[0m\n", + "\u001b[01;34m'July 15 Term'\u001b[0m\n", + "\u001b[01;34m'July 16 Term'\u001b[0m\n", + "\u001b[01;34m'July 17 Term'\u001b[0m\n", + "\u001b[01;34m'July 18 Term'\u001b[0m\n", + " \u001b[01;34mKaharole_Bridge\u001b[0m\n", + "\u001b[01;34m'Lab Sheet'\u001b[0m\n", + "\u001b[01;34m'Learn Excel'\u001b[0m\n", + " LinearScalingBiasCorrectionV.1.0.xlsx\n", + " MAC_Collect_Notice.pdf\n", + " Map.docx\n", + "\u001b[01;34m'Matagorda_HMS Model'\u001b[0m\n", + "'Meal Calculation Arifur Rahman (July 1-15) 2016.xlsx'\n", + " Minutes_BUGS_WRE_BUET.pdf\n", + "'MSc admission April 2017 Semester (Equivalence).xlsx'\n", + "'M.Sc. Engg. Admission April 2017 (Degree Equivalence).docx'\n", + " M.Sc_WRE_6501.pdf\n", + " \u001b[01;34mMuhuri\u001b[0m\n", + " \u001b[01;34mNafi_data\u001b[0m\n", + " NID.docx\n", + " \u001b[01;35mNID.jpg\u001b[0m\n", + " NID.pdf\n", + " \u001b[01;34mNSU\u001b[0m\n", + " \u001b[01;34mNuffic_\u001b[0m\n", + " \u001b[01;34mNuffic_155\u001b[0m\n", + " pad.wre.docx\n", + "'Pay_Scale For Public_Univ.Treachers.pdf'\n", + " \u001b[01;31mPHSetup.zip\u001b[0m\n", + " \u001b[01;34mpython-3.6.5-docs-pdf-letter\u001b[0m\n", + "'Question Format.doc'\n", + "'Question Format.docx'\n", + "\u001b[01;34m'Recommendations for Students'\u001b[0m\n", + "'Request_Recommendation(2).pdf'\n", + " Resume-of-Arif.pdf\n", + "'Resume of Md Arifur Rahman.pdf'\n", + " \u001b[01;34mR-Studio\u001b[0m\n", + " \u001b[01;34mSandwip\u001b[0m\n", + " \u001b[01;34mSonagaon\u001b[0m\n", + " Statistical_Methods.docx\n", + " \u001b[01;31mStatistical-Methods-in-Hydrology-C-T-HaaN.zip\u001b[0m\n", + " StudentGradeSheet.pdf\n", + " \u001b[01;34mSWAT_DATA\u001b[0m\n", + " Syllabus_WRE.pdf\n", + " \u001b[01;34mTAX-2015-2016\u001b[0m\n", + " \u001b[01;34mTOEFL_Triumph\u001b[0m\n", + " \u001b[01;34mUGC\u001b[0m\n", + " Uni_Teacher_Uniform_Upgradation_Rules_Drafted_by_UGC.pdf\n", + "\u001b[01;34m'US Visa 2018'\u001b[0m\n", + "\u001b[01;34m'UTA_Fall 2018'\u001b[0m\n", + " \u001b[01;34mVideo\u001b[0m\n", + " \u001b[01;34mWallpapers\u001b[0m\n", + " \u001b[01;34mWedding_Photos_Vedios\u001b[0m\n", + "\u001b[01;34m'Wedding Sweety'\u001b[0m\n", + "\u001b[01;34m'WRE 404- Excersizes'\u001b[0m\n", + "\u001b[01;34m'WRE 428_GIS'\u001b[0m\n", + " \u001b[01;34mWRE_Curriculum\u001b[0m\n", + " \u001b[01;34mWrite-up\u001b[0m\n", + "\u001b[01;35m'www (1).weddingdiary.bd.com190-1.jpg'\u001b[0m\n", + " \u001b[01;35mwww.weddingdiary.bd.com190-1.jpg\u001b[0m\n", + " \u001b[01;34mX-sections_Data\u001b[0m\n", + " \u001b[01;34mX-Trail\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1441\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# ls\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# mkdir Lab-1-Solutions\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mLab-1-Solutions\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# cd Lab-1-Solutions\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# ls\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o38c4lbsqvzy", + "colab_type": "text" + }, + "source": [ + "## Exploring Unix Filesystem\n", + "\n", + "You can look at the root directory of the system by issuing \"ls /\". As explained in lecture, Unix uses the file system to communicate with devices and between processes. \"/etc\" keeps the configuration files of the system. \"/bin\" and \"/sbin\" store most of the standard Unix programs. \"/usr\" stores installes programs and their associate files, with \"/usr/bin\" usually storing the commands you can run. \n", + "\n", + "*Exercise 3:* List the \"/dev\" directory. How many SSD storage devices do you see? How many partitions does each device have? (Answer in box below)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yNj2LXzP2ksl", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "5d7696b9-1245-4164-ba03-8e7f4411320c" + }, + "source": [ + "!/bin/bash --noediting\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (123): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@4a3f943c3636: /content/sample_data\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mbin\u001b[0m \u001b[01;34metc\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34msys\u001b[0m\n", + "\u001b[01;34mboot\u001b[0m \u001b[01;34mhome\u001b[0m \u001b[01;34mproc\u001b[0m \u001b[01;34mtensorflow-2.1.0\u001b[0m\n", + "\u001b[01;34mcontent\u001b[0m \u001b[01;34mlib\u001b[0m \u001b[01;34mroot\u001b[0m \u001b[30;42mtmp\u001b[0m\n", + "\u001b[01;34mdatalab\u001b[0m \u001b[01;34mlib32\u001b[0m \u001b[01;34mrun\u001b[0m \u001b[01;34mtools\u001b[0m\n", + "\u001b[01;34mdev\u001b[0m \u001b[01;34mlib64\u001b[0m \u001b[01;34msbin\u001b[0m \u001b[01;34musr\u001b[0m\n", + "dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl \u001b[01;34mmedia\u001b[0m \u001b[01;34msrv\u001b[0m \u001b[01;34mvar\u001b[0m\n", + "dlib-19.18.0-cp36-cp36m-linux_x86_64.whl \u001b[01;34mmnt\u001b[0m \u001b[01;34mswift\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /etc\n", + "\u001b]0;root@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /dev\n", + "\u001b]0;root@4a3f943c3636: /dev\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/dev\u001b[00m# ls\n", + "\u001b[0m\u001b[01;36mcore\u001b[0m \u001b[40;33;01mfull\u001b[0m \u001b[30;42mmqueue\u001b[0m \u001b[01;36mptmx\u001b[0m \u001b[40;33;01mrandom\u001b[0m \u001b[01;36mstderr\u001b[0m \u001b[01;36mstdout\u001b[0m \u001b[40;33;01murandom\u001b[0m\n", + "\u001b[01;36mfd\u001b[0m \u001b[40;33;01mfuse\u001b[0m \u001b[40;33;01mnull\u001b[0m \u001b[01;34mpts\u001b[0m \u001b[30;42mshm\u001b[0m \u001b[01;36mstdin\u001b[0m \u001b[40;33;01mtty\u001b[0m \u001b[40;33;01mzero\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /dev\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/dev\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# ll\n", + "total 7916\n", + "drwxr-xr-x 1 root root 4096 Feb 7 19:24 \u001b[0m\u001b[01;34m.\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 7 19:24 \u001b[01;34m..\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:29 \u001b[01;34mbin\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Apr 24 2018 \u001b[01;34mboot\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 7 20:13 \u001b[01;34mcontent\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 6 17:43 \u001b[01;34mdatalab\u001b[0m/\n", + "drwxr-xr-x 5 root root 360 Feb 7 19:24 \u001b[01;34mdev\u001b[0m/\n", + "-rw-r--r-- 1 root root 3989833 Feb 6 17:12 dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl\n", + "-rw-r--r-- 1 root root 3997028 Feb 6 17:12 dlib-19.18.0-cp36-cp36m-linux_x86_64.whl\n", + "-rwxr-xr-x 1 root root 0 Feb 7 19:24 \u001b[01;32m.dockerenv\u001b[0m*\n", + "drwxr-xr-x 1 root root 4096 Feb 7 19:24 \u001b[01;34metc\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Apr 24 2018 \u001b[01;34mhome\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:31 \u001b[01;34mlib\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Feb 5 18:27 \u001b[01;34mlib32\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Oct 29 21:25 \u001b[01;34mlib64\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Oct 29 21:25 \u001b[01;34mmedia\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Oct 29 21:25 \u001b[01;34mmnt\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:32 \u001b[01;34mopt\u001b[0m/\n", + "dr-xr-xr-x 115 root root 0 Feb 7 19:24 \u001b[01;34mproc\u001b[0m/\n", + "drwx------ 1 root root 4096 Feb 7 20:13 \u001b[01;34mroot\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:29 \u001b[01;34mrun\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:31 \u001b[01;34msbin\u001b[0m/\n", + "drwxr-xr-x 2 root root 4096 Oct 29 21:25 \u001b[01;34msrv\u001b[0m/\n", + "drwxr-xr-x 4 root root 4096 Feb 6 17:42 \u001b[01;34mswift\u001b[0m/\n", + "dr-xr-xr-x 12 root root 0 Feb 7 19:24 \u001b[01;34msys\u001b[0m/\n", + "drwxr-xr-x 4 root root 4096 Feb 6 17:38 \u001b[01;34mtensorflow-2.1.0\u001b[0m/\n", + "drwxrwxrwt 1 root root 4096 Feb 7 20:13 \u001b[30;42mtmp\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 6 17:43 \u001b[01;34mtools\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:32 \u001b[01;34musr\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 7 19:24 \u001b[01;34mvar\u001b[0m/\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /etc\n", + "\u001b]0;root@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# ls\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@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cd passwd\n", + "bash: cd: passwd: Not a directory\n", + "\u001b]0;root@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cd /passwd\n", + "bash: cd: /passwd: No such file or directory\n", + "\u001b]0;root@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mbin\u001b[0m \u001b[01;34metc\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34msys\u001b[0m\n", + "\u001b[01;34mboot\u001b[0m \u001b[01;34mhome\u001b[0m \u001b[01;34mproc\u001b[0m \u001b[01;34mtensorflow-2.1.0\u001b[0m\n", + "\u001b[01;34mcontent\u001b[0m \u001b[01;34mlib\u001b[0m \u001b[01;34mroot\u001b[0m \u001b[30;42mtmp\u001b[0m\n", + "\u001b[01;34mdatalab\u001b[0m \u001b[01;34mlib32\u001b[0m \u001b[01;34mrun\u001b[0m \u001b[01;34mtools\u001b[0m\n", + "\u001b[01;34mdev\u001b[0m \u001b[01;34mlib64\u001b[0m \u001b[01;34msbin\u001b[0m \u001b[01;34musr\u001b[0m\n", + "dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl \u001b[01;34mmedia\u001b[0m \u001b[01;34msrv\u001b[0m \u001b[01;34mvar\u001b[0m\n", + "dlib-19.18.0-cp36-cp36m-linux_x86_64.whl \u001b[01;34mmnt\u001b[0m \u001b[01;34mswift\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /etc/passwd\n", + "bash: cd: /etc/passwd: Not a directory\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /etc\n", + "\u001b]0;root@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# ls\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@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cat 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@4a3f943c3636: /etc\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/etc\u001b[00m# cd ..\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mbin\u001b[0m \u001b[01;34metc\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34msys\u001b[0m\n", + "\u001b[01;34mboot\u001b[0m \u001b[01;34mhome\u001b[0m \u001b[01;34mproc\u001b[0m \u001b[01;34mtensorflow-2.1.0\u001b[0m\n", + "\u001b[01;34mcontent\u001b[0m \u001b[01;34mlib\u001b[0m \u001b[01;34mroot\u001b[0m \u001b[30;42mtmp\u001b[0m\n", + "\u001b[01;34mdatalab\u001b[0m \u001b[01;34mlib32\u001b[0m \u001b[01;34mrun\u001b[0m \u001b[01;34mtools\u001b[0m\n", + "\u001b[01;34mdev\u001b[0m \u001b[01;34mlib64\u001b[0m \u001b[01;34msbin\u001b[0m \u001b[01;34musr\u001b[0m\n", + "dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl \u001b[01;34mmedia\u001b[0m \u001b[01;34msrv\u001b[0m \u001b[01;34mvar\u001b[0m\n", + "dlib-19.18.0-cp36-cp36m-linux_x86_64.whl \u001b[01;34mmnt\u001b[0m \u001b[01;34mswift\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/\u001b[00m# cd /content\n", + "\u001b]0;root@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\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@4a3f943c3636: /content\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive/My\\ Drive\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# ls\n", + " 010-CV_BRTC-Arif-2017.docx\n", + " \u001b[0m\u001b[01;35m20170317_112443.jpg\u001b[0m\n", + " \u001b[01;35m20180221_110637.jpg\u001b[0m\n", + " 6-15_math-bangla.pdf\n", + "'Application Form.pdf'\n", + " \u001b[01;34mApplication_USA\u001b[0m\n", + "\u001b[01;34m'Arif-M.Sc Presentation'\u001b[0m\n", + "'Arif_Pad (1).docx'\n", + " Arif_Pad.docx\n", + "\u001b[01;34m'Auto Call Recorder'\u001b[0m\n", + "'BD map.gmap'\n", + " \u001b[01;34mBirthday_Aishy\u001b[0m\n", + " \u001b[01;34mBRTC_Secretary\u001b[0m\n", + " \u001b[01;35mBUET.png\u001b[0m\n", + " \u001b[01;34mBUGS_Secretary\u001b[0m\n", + "\u001b[01;34m'Car Ownership Transfer'\u001b[0m\n", + "\u001b[01;34m'Colab Notebooks'\u001b[0m\n", + " \u001b[01;34mConvener\u001b[0m\n", + "'CV_Academic_ Arif.pdf'\n", + " CV_BRTC-Arif.doc\n", + " \u001b[01;34mData-1441\u001b[0m\n", + " \u001b[01;34mDelft3D_manuals\u001b[0m\n", + " document.pdf\n", + " \u001b[01;35mdr-ferdousi-islam-lipi_70_1.jpg\u001b[0m\n", + "\u001b[01;34m'Duncan Brothers Ltd'\u001b[0m\n", + "\u001b[01;34m'Earthquake Assignment'\u001b[0m\n", + " \u001b[01;34mEbook\u001b[0m\n", + " \u001b[01;34mE_Flow_Gorai\u001b[0m\n", + "\u001b[01;34m'Ehsan Vai'\u001b[0m\n", + " \u001b[01;34mEnglish_Learning\u001b[0m\n", + " excel.pdf\n", + " ex_routine_final.pdf\n", + " Final_List_of_Group_A_House_05.02.2017.xls\n", + " Flow_Duration_Tutorial_DL_File.xls\n", + " folder-lock-en.exe\n", + "\u001b[01;34m'For Sheola Hydrology expert'\u001b[0m\n", + "\u001b[01;34m'From Dropbox'\u001b[0m\n", + " \u001b[01;34mGeoSWMM\u001b[0m\n", + " \u001b[01;34mGIS\u001b[0m\n", + "\u001b[01;34m'Google Photos'\u001b[0m\n", + "\u001b[01;34m'GPS Data Extraction'\u001b[0m\n", + " Grade_Sheet_Preparation.xlsx\n", + " \u001b[01;34mGRE_Triumph\u001b[0m\n", + " \u001b[01;34mHEC-Soft\u001b[0m\n", + " \u001b[01;34mHEQEP\u001b[0m\n", + " house_allotment_A.pdf\n", + "'Invitation List for Marriage Ceremony.docx'\n", + " Item_Nuffic_PnD.docx\n", + "\u001b[01;34m'January 15 Term'\u001b[0m\n", + "\u001b[01;34m'January 16 Term'\u001b[0m\n", + "\u001b[01;34m'January 17 Term'\u001b[0m\n", + "\u001b[01;34m'January 18 Term'\u001b[0m\n", + " \u001b[01;34mJFCL\u001b[0m\n", + " \u001b[01;34mJFCL_Visit\u001b[0m\n", + "\u001b[01;34m'July 14 Term'\u001b[0m\n", + "\u001b[01;34m'July 15 Term'\u001b[0m\n", + "\u001b[01;34m'July 16 Term'\u001b[0m\n", + "\u001b[01;34m'July 17 Term'\u001b[0m\n", + "\u001b[01;34m'July 18 Term'\u001b[0m\n", + " \u001b[01;34mKaharole_Bridge\u001b[0m\n", + "\u001b[01;34m'Lab Sheet'\u001b[0m\n", + "\u001b[01;34m'Learn Excel'\u001b[0m\n", + " LinearScalingBiasCorrectionV.1.0.xlsx\n", + " MAC_Collect_Notice.pdf\n", + " Map.docx\n", + "\u001b[01;34m'Matagorda_HMS Model'\u001b[0m\n", + "'Meal Calculation Arifur Rahman (July 1-15) 2016.xlsx'\n", + " Minutes_BUGS_WRE_BUET.pdf\n", + "'MSc admission April 2017 Semester (Equivalence).xlsx'\n", + "'M.Sc. Engg. Admission April 2017 (Degree Equivalence).docx'\n", + " M.Sc_WRE_6501.pdf\n", + " \u001b[01;34mMuhuri\u001b[0m\n", + " \u001b[01;34mNafi_data\u001b[0m\n", + " NID.docx\n", + " \u001b[01;35mNID.jpg\u001b[0m\n", + " NID.pdf\n", + " \u001b[01;34mNSU\u001b[0m\n", + " \u001b[01;34mNuffic_\u001b[0m\n", + " \u001b[01;34mNuffic_155\u001b[0m\n", + " pad.wre.docx\n", + "'Pay_Scale For Public_Univ.Treachers.pdf'\n", + " \u001b[01;31mPHSetup.zip\u001b[0m\n", + " \u001b[01;34mpython-3.6.5-docs-pdf-letter\u001b[0m\n", + "'Question Format.doc'\n", + "'Question Format.docx'\n", + "\u001b[01;34m'Recommendations for Students'\u001b[0m\n", + "'Request_Recommendation(2).pdf'\n", + " Resume-of-Arif.pdf\n", + "'Resume of Md Arifur Rahman.pdf'\n", + " \u001b[01;34mR-Studio\u001b[0m\n", + " \u001b[01;34mSandwip\u001b[0m\n", + " \u001b[01;34mSonagaon\u001b[0m\n", + " Statistical_Methods.docx\n", + " \u001b[01;31mStatistical-Methods-in-Hydrology-C-T-HaaN.zip\u001b[0m\n", + " StudentGradeSheet.pdf\n", + " \u001b[01;34mSWAT_DATA\u001b[0m\n", + " Syllabus_WRE.pdf\n", + " \u001b[01;34mTAX-2015-2016\u001b[0m\n", + " \u001b[01;34mTOEFL_Triumph\u001b[0m\n", + " \u001b[01;34mUGC\u001b[0m\n", + " Uni_Teacher_Uniform_Upgradation_Rules_Drafted_by_UGC.pdf\n", + "\u001b[01;34m'US Visa 2018'\u001b[0m\n", + "\u001b[01;34m'UTA_Fall 2018'\u001b[0m\n", + " \u001b[01;34mVideo\u001b[0m\n", + " \u001b[01;34mWallpapers\u001b[0m\n", + " \u001b[01;34mWedding_Photos_Vedios\u001b[0m\n", + "\u001b[01;34m'Wedding Sweety'\u001b[0m\n", + "\u001b[01;34m'WRE 404- Excersizes'\u001b[0m\n", + "\u001b[01;34m'WRE 428_GIS'\u001b[0m\n", + " \u001b[01;34mWRE_Curriculum\u001b[0m\n", + " \u001b[01;34mWrite-up\u001b[0m\n", + "\u001b[01;35m'www (1).weddingdiary.bd.com190-1.jpg'\u001b[0m\n", + " \u001b[01;35mwww.weddingdiary.bd.com190-1.jpg\u001b[0m\n", + " \u001b[01;34mX-sections_Data\u001b[0m\n", + " \u001b[01;34mX-Trail\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1441\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mLab-1-Solutions\u001b[0m\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# cd Lab-1-Solutions\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# ls\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# cat > favorite-colors-list.txt Red Blue Pink \n", + "cat: Red: No such file or directory\n", + "cat: Blue: No such file or directory\n", + "cat: Pink: No such file or directory\n", + "\u001b]0;root@4a3f943c3636: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@4a3f943c3636\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# cat > favorite-colors-list.txt\n", + "Red Pink White Blue\n", + "ls\n", + "cat favorite-colors-list.txt\n", + "^D\n", + "exit\n", + "control-d\n", + "D\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YRgFGdyHU5xM", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting\n", + "1 SSD and one partition " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7P9EG0KOqvz2", + "colab_type": "text" + }, + "source": [ + "## Text File Manipulation\n", + "\n", + "As explained in lecture, Unix stores most information in text files. For example, the list of all users and their home directories are stored in \"/etc/passwd\". Let get some familiarity with the most commonly used commands to manipulate files.\n", + "\n", + " - You can see the contents contents a file using the \"cat\" (concatenate) command. Try executing \"cat /etc/passwd\". You'll get a huge list that will go by your screen quickly. \n", + " \n", + " - To go through the file page by page, you can use the \"less\" or \"more\" commands. \n", + " \n", + " - You can see the first or last N (N=10 by default) lines of a file using \"head\" or \"tail\" commands. For example \"tail -20 /etc/passwd\" will list the last 20 lines. \n", + " \n", + " - You can search a test file using the \"grep\" command, which takes a string keyword as the first argument and a filename as the second, and by default prints out every line in the file that contrains the string. So for example you can do \"grep \\$USER /etc/passwd\" to find the line corresponding to your account. Some useful flags: \n", + " \n", + " - \"-i\" ignores the case of the keyword\n", + " - \"-v\" display those lines that do NOT match \n", + " - \"-n\" precede each matching line with the line number \n", + " - \"-c\" print only the total count of matched lines \n", + " \n", + " For example \"grep -c \\$USER /etc/passwd\" should show that you are in the password file just once. \n", + " \n", + " - The \"wc\" (word count) command counts the number of lines, words, and characters in a file. By default \"wc\" gives you all three numbers, but \"-w\", \"-l\", or \"-c\" flags \n", + "\n", + "*Exercise 4:* Count how many lines in the password file contain the letter \"w\". " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "UlsANMuf2qMs", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting\n", + "cat /etc/passwd\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SZuhLbD8qvz5", + "colab_type": "text" + }, + "source": [ + "## Redirection\n", + "\n", + "Unix provides programs \"pipes\" for input and output. Most of what you see on the screen when you run a program was written to the \"stdout\" (standard output) pipe. Other pipes are \"stdin\" (standard input) and \"stderr\" (standard error), where error messages are written.\n", + "\n", + "As discussed in lecture, the basic commands of are simple, but you can chain them to do complicated things. Redirection is how you chain these commands, directing the output of one command to the input of the next.\n", + "\n", + "As an example, consider the \"cat\" command. Cat takes stdin and outputs it to stdout. Type \"cat\" and press enter and confirm. You can get back to the command prompt by pressing \"control-c\" (sends terminate singal) or \"control-d\" (end of file character). Note that from now on we will use the convention: \"control-d\" = \"^D\"\n", + "\n", + "*Exercise 5a:* Using \"cat\" and indirection you can write things into a file. The \">\" symbol directs stdout into a file. Try \"cat > favorite-colors-list.txt\" and then type in your 3 favorite colors, each on it's own line. Use \"^D\" to end your input." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gw3S4O0zIVmK", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H5vxtcXnqvz6", + "colab_type": "text" + }, + "source": [ + "Use \"cat\", \"more\", or \"less\" to confirm that you file is as you expect it. \">>\" allows you to append to the file. \n", + "\n", + "*Exercise 5b:* Append 2 more colors to your file." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "twRKNaGy3XGw", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DZODNKiAqvz8", + "colab_type": "text" + }, + "source": [ + "The \"sort\" command sorts what it sees on stdin. Instead of taking input from the terminal, you can direct the shell to take stdin from a file using \"<\". Try \"sort < favorite-color-list.txt\" and \"sort < favorite-color-list.txt > sorted-favorite-color-list.txt\".\n", + "\n", + "Finally, instead of piping input / output into files, you can directly chain one program into another using \"|\". So for example, you can do \"cat /etc/passwd | grep -i \\$USER | wc -l\". \n", + "\n", + "*Exercise 5c:* Use indirection to count the number of users on TACC with your first name. Copy the command you used into box below." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "oP9XlZl_3iZD", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "v5IaZXNyqvz_", + "colab_type": "text" + }, + "source": [ + "## Git\n", + "\n", + "`git` is a Version Control System (VCS), typically used to organize the source code of software project but also good source of documents or web-pages. An instance of `git` server stores repositories, each typically containing the code relevant to a specific project. Users create local `clones` of repositories, change and develop the local copies of the code, `commit` the changes to their local repository, `push` to the server as a contribution, \n", + "`pull` updates from the server, and `merge` changes between local and remote versions. \n", + "\n", + "Besides cloning, repositories can be branched or forked. A repository generally starts with a `master` branch that evolves as push requests are merged in. Creating a new branch from an existing branch creates a snapshot of the which can evolve independently or be merged in later. Branches are easy to make and delete, and can serve various purposes. They can represent a stable version of software package. Or a parallel development for different operating system. A fork of a repository is a standalone instance of the repository which can be stored and managed independently from the original, where you can work independently without constraints or interference. \n", + "\n", + "[GitHub](github.com) provides a massive publically accessible instance of a `git` system besides sharing code, projects can be developed by the open source community. It provides tools for managing your repository and a wiki for documentation. Contributions to public software on GitHub generally require making a merge request which would be judged by the managers of the repository. That's why most software packages enourage you to create a new fork, so you can work independently.\n", + "\n", + "Lets take a look at some repositories:\n", + "\n", + "* [This class](https://github.com/afarbin/DATA1401-Spring-2020)\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "J_R64sQDqv0A", + "colab_type": "text" + }, + "source": [ + "## Plan\n", + "\n", + "You made a clone of the class repository at start of this lab. We will create a new fork where you can keep track and submit your work, following [these instructions](https://help.github.com/articles/fork-a-repo/).\n", + "\n", + "Goto to github.com and log in.\n", + "\n", + "Next, lets create a fork of the [class repository](https://github.com/afarbin/DATA1401-Spring-2019). Click the link and press the \"Fork\" button on the top right. Select your repository as where you want to place the fork.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "edTvE6rOqv0C", + "colab_type": "text" + }, + "source": [ + "Now we will check out your fork in your Google Drive / Colab.\n", + "\n", + "Note: Jupyter allows you to run shell directly in a notebook. We will use `!` and `%` to call shell commands directly in this notebook. Follow along yourself. Either create a new notebook or open a terminal. \n", + "\n", + "Start by listing the contents of your current directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "e5tXg0f8qv0D", + "colab_type": "code", + "outputId": "c1efce86-1492-4f31-ad23-182380465c68", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 71 + } + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[Errno 2] No such file or directory: '/content/drive/My Drive'\n", + "/content\n", + "sample_data\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "WYsyYcg1qv0J", + "colab_type": "text" + }, + "source": [ + "Make a new directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Z7noY1hMqv0L", + "colab_type": "code", + "outputId": "5e8d0749-78e7-49e4-f76f-1b00faaccf70", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/Data-1401-Repo\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fwsBdTnYqv0Q", + "colab_type": "text" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cOAuqTVUqv0V", + "colab_type": "text" + }, + "source": [ + "Go into the directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8w42MH6Jqv0S", + "colab_type": "code", + "outputId": "74ec0b78-e263-4d36-a4f7-f9ef3021c2cc", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "source": [ + "# What you past here should look like:\n", + "!git clone https://github.com//DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/bin/bash: your: No such file or directory\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vL6KZOm0r6tf", + "colab_type": "code", + "outputId": "847d0121-6ad2-40b5-ad28-348f70209380", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 142 + } + }, + "source": [ + "!git clone https://github.com/afarbin/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Cloning into 'DATA1401-Spring-2020'...\n", + "remote: Enumerating objects: 104, done.\u001b[K\n", + "remote: Counting objects: 100% (104/104), done.\u001b[K\n", + "remote: Compressing objects: 100% (67/67), done.\u001b[K\n", + "remote: Total 104 (delta 24), reused 90 (delta 19), pack-reused 0\u001b[K\n", + "Receiving objects: 100% (104/104), 28.84 MiB | 45.64 MiB/s, done.\n", + "Resolving deltas: 100% (24/24), done.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "b1Ew4tEZqv0X", + "colab_type": "code", + "outputId": "466c227e-6824-4b92-c780-24de66dcd540", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 53 + } + }, + "source": [ + "%cd DATA1401-Spring-2020\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/Data-1401-Repo/DATA1401-Spring-2020\n", + "Labs Lectures\tREADME.md syllabus.pdf\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IrhWToc-qv0a", + "colab_type": "text" + }, + "source": [ + "We will now connect your fork to the original so you can pull changes from there. \n", + "\n", + "Check remote status:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JxtMYR-9qv0c", + "colab_type": "code", + "outputId": "784198a9-28ca-435c-b4ee-0e33605d4b16", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 53 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/afarbin/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/afarbin/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9ud3X0fBqv0f", + "colab_type": "text" + }, + "source": [ + "Now use the original class URL to set your upstream:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "pgJlKxBqqv0h", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "id2yUEt9qv0k", + "colab_type": "code", + "outputId": "eae4b78a-4974-4daf-d17c-0fbeb6062ee0", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 53 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/afarbin/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/afarbin/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sAkgeJ6Iqv0n", + "colab_type": "text" + }, + "source": [ + "From now on, you can get the newest version of class material by using:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AGDsfTFLqv0o", + "colab_type": "code", + "outputId": "5684fb8f-87db-44eb-b334-58108c8e6fac", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 35 + } + }, + "source": [ + "!git pull" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Already up to date.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u9RAhs5b4vXY", + "colab_type": "text" + }, + "source": [ + "We will submit your Lab 1 using git at the next Lab." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PPfGmFQI40HR", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file From 0ea52d3b6744b76863852e23bd5ccd3d2dab549b Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Wed, 12 Feb 2020 16:44:26 -0600 Subject: [PATCH 02/12] Add files via upload --- Downloading_code.ipynb | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Downloading_code.ipynb diff --git a/Downloading_code.ipynb b/Downloading_code.ipynb new file mode 100644 index 0000000..cc62611 --- /dev/null +++ b/Downloading_code.ipynb @@ -0,0 +1,6 @@ +%cd /content/drive/My\ Drive +%cd Data-1401-Repo +#We will now connect your fork to the original so you can pull changes from there. +!git remote -v +#From now on, you can get the newest version of class material by using: +!git pull \ No newline at end of file From 3c6aaaf0b96dea0f97b024d5c9a0b42d27e8a8d4 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 14 Feb 2020 13:10:12 -0600 Subject: [PATCH 03/12] Add files via upload Submission from mxr8032, UTA ID: 1001618032, Md Arifur Rahman --- Labs/Lab-2/Lab-2_Md_Arifur_Rahman.ipynb | 560 ++++++++++++++++++++++++ 1 file changed, 560 insertions(+) create mode 100644 Labs/Lab-2/Lab-2_Md_Arifur_Rahman.ipynb diff --git a/Labs/Lab-2/Lab-2_Md_Arifur_Rahman.ipynb b/Labs/Lab-2/Lab-2_Md_Arifur_Rahman.ipynb new file mode 100644 index 0000000..99a8a74 --- /dev/null +++ b/Labs/Lab-2/Lab-2_Md_Arifur_Rahman.ipynb @@ -0,0 +1,560 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#Exercise 1: Write 2 functions even(x) and odd(x) \n", + "#that take an integer and returns True if the input is even or odd, otherwise returns False.\n", + "# Write you solution here\n", + "def even(x):\n", + " return x%2==0\n", + "def odd(x):\n", + " return x%2!=0" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Testing 2 if Even : True\n", + "Testing 3 if Even : False\n", + "Testing 4 if Even : True\n", + "Testing 5 if odd : True\n", + "Testing 6 if odd : False\n", + "Testing 7 if odd : True\n", + "Testing 246465 if odd : True\n", + "Testing 4634650 if Even : True\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "print(\"Testing 2 if Even :\", even(2))\n", + "print(\"Testing 3 if Even :\", even(3))\n", + "print(\"Testing 4 if Even :\", even(4))\n", + "print(\"Testing 5 if odd :\", odd(5))\n", + "print(\"Testing 6 if odd :\", odd(6))\n", + "print(\"Testing 7 if odd :\", odd(7))\n", + "print(\"Testing 246465 if odd :\", odd(246465))\n", + "print(\"Testing 4634650 if Even :\", even(463460))" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [], + "source": [ + "#Exercise 2: Write a function that takes a list of numbers as input \n", + "#and returns a list of the subset of elements that are less that 10\n", + "# Write you solution here\n", + "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\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 4, 5, 0, 2, 9, -45, -12, -7]\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "print(less_than_ten([1,3,4,5,12,0,45,2,9,452,-45,-12,-7,56,123]))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "#Exercise 3: Write a function that takes a number x_max as input \n", + "#and returns a function that performs the same task as exercise 2, \n", + "#but for x_max instead of 10.\n", + "# Write you solution here\n", + "def less_than_xmax(lst):\n", + " x_max = max(lst)\n", + " out_list = list()\n", + " for element in lst:\n", + " if element = 2:\n", + " fibonnaci_list.append(p)\n", + " fibonnaci_list.append(q)\n", + " \n", + " for i in range(2,n):\n", + " r = p + q\n", + " p = q\n", + " q = r\n", + " #print(\",{}\".format(r),end=\"\")\n", + " fibonnaci_list.append(r)\n", + " return fibonnaci_list\n" + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]" + ] + }, + "execution_count": 49, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "#fibonnaci(-10)\n", + "#fibonnaci(0)\n", + "fibonnaci(10)\n", + "#fibonnaci(15)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 64, + "metadata": {}, + "outputs": [], + "source": [ + "#Exercise 9: Write a function that takes a string of consisting of several words \n", + "#and returns a string that reverses the order of the words.\n", + "# Write you solution here\n", + "def reverse_words(word_list):\n", + " reversed_list = list()\n", + " word_list.reverse()\n", + " reversed_list.append(word_list)\n", + " return reversed_list\n" + ] + }, + { + "cell_type": "code", + "execution_count": 70, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[['Banna', 'Almod', 'Orange', 'Pineapple', 'Mango', 'Apple']]" + ] + }, + "execution_count": 70, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "reverse_words([\"Apple\", \"Mango\", \"Pineapple\", \"Orange\",\"Almod\",\"Banna\"])\n", + "#reverse_words([\"Arif\", \"Nabin\", \"Dr. Eapi\", \"Vaghef\",\"Ali\",\"Ann\",\"Helia\",\"Farhad\", \"Fahad\",\"Babak\",\"Rahman\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hello! What is your name?\n", + "Arif\n", + "Well, Arif, I am thinking of a number between 1 and 20.\n", + "Take a guess.\n", + "9\n", + "Your guess is too low.\n", + "Take a guess.\n", + "12\n", + "Your guess is too high.\n", + "Take a guess.\n", + "10\n", + "Good job, Arif! You guessed my number in 3 guesses!\n" + ] + } + ], + "source": [ + "#Exercise 10: Write a guessing game program that will repeatedly guess a number that the users picks,\n", + "#with the user indicating higher or lower, until it correctly guesses the number.\n", + "# Write you solution here\n", + "import random\n", + "guessesTaken = 0\n", + "print('Hello! What is your name?')\n", + "myName = input()\n", + "number = random.randint(1, 20)\n", + "print('Well, ' + myName + ', I am thinking of a number between 1 and 20.')\n", + "\n", + "while guessesTaken < 6:\n", + " print('Take a guess.')\n", + " guess = input()\n", + " guess = int(guess)\n", + " guessesTaken = guessesTaken + 1\n", + "\n", + " if guess < number:\n", + " print('Your guess is too low.') # There are eight spaces in front of print.\n", + "\n", + " if guess > number:\n", + " print('Your guess is too high.')\n", + "\n", + " if guess == number:\n", + " break\n", + "if guess == number:\n", + " guessesTaken = str(guessesTaken)\n", + " print('Good job, ' + myName + '! You guessed my number in ' + guessesTaken + ' guesses!')\n", + "\n", + "if guess != number:\n", + " number = str(number)\n", + " print('Nope. The number I was thinking of was ' + number)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Test your solution here" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.7.4" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 58676d6c2c56cc4b36832f9aa5430d6bd2e205c1 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Mon, 17 Feb 2020 22:23:08 -0600 Subject: [PATCH 04/12] Add files via upload --- Labs/Lab-1/Lab-1-Submission.ipynb | 1277 +++++++++++++++++++++++++++++ 1 file changed, 1277 insertions(+) create mode 100644 Labs/Lab-1/Lab-1-Submission.ipynb diff --git a/Labs/Lab-1/Lab-1-Submission.ipynb b/Labs/Lab-1/Lab-1-Submission.ipynb new file mode 100644 index 0000000..6317306 --- /dev/null +++ b/Labs/Lab-1/Lab-1-Submission.ipynb @@ -0,0 +1,1277 @@ +{ + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "KJ5f-WO0wcAv" + }, + "outputs": [], + "source": [ + "!ls\n", + "!echo \"----------\"\n", + "!ls sample_data" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 126 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 21425, + "status": "ok", + "timestamp": 1581996185878, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "MB5EqdO-Uby-", + "outputId": "163244fb-1329-4b8e-e42a-6d01136cf1fb" + }, + "outputs": [ + { + "name": "stdout", + "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" + ] + } + ], + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ] + }, + { + "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", + "execution_count": 2, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 71 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 3358, + "status": "ok", + "timestamp": 1581996195360, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "99nrBYTWxZJr", + "outputId": "65817594-0eb7-479a-cc06-9eb249791ee6" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Technique 1:\n", + "drive sample_data\n", + "drive sample_data\n" + ] + } + ], + "source": [ + "!echo \"Technique 1:\"\n", + "!ls\n", + "!cd sample_data\n", + "!ls" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 106 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 1882, + "status": "ok", + "timestamp": 1581996201790, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "2-Znf97Lxl-Z", + "outputId": "62a74723-44fd-4b18-9758-d0d7641b5324" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Technique 2:\n", + "drive sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ] + } + ], + "source": [ + "!echo \"Technique 2:\"\n", + "!ls ; cd sample_data ;ls" + ] + }, + { + "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", + "execution_count": 4, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 124 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 3059, + "status": "ok", + "timestamp": 1581996224759, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "vLBPTX4rx3gd", + "outputId": "0356b823-d72a-48c7-d231-af686d383138" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Technique 3:\n", + "drive sample_data\n", + "/content/sample_data\n", + "anscombe.json\t\t mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv README.md\n" + ] + } + ], + "source": [ + "!echo \"Technique 3:\"\n", + "!ls \n", + "%cd sample_data \n", + "!ls" + ] + }, + { + "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", + "execution_count": 5, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 339 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 51442, + "status": "ok", + "timestamp": 1581996349687, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "MIDFitLZyuZy", + "outputId": "d011f5be-9154-4fb6-f917-02d9ef71bd5d" + }, + "outputs": [ + { + "name": "stdout", + "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@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ls\n", + "\u001b[0m\u001b[01;32manscombe.json\u001b[0m mnist_test.csv\n", + "california_housing_test.csv mnist_train_small.csv\n", + "california_housing_train.csv \u001b[01;32mREADME.md\u001b[0m\n", + "\u001b]0;root@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# ll\n", + "total 20\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:23 \u001b[0m\u001b[01;34m.\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:18 \u001b[01;34m..\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 13 17:15 \u001b[01;34m.config\u001b[0m/\n", + "drwx------ 4 root root 4096 Feb 18 03:23 \u001b[01;34mdrive\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:37 \u001b[01;34msample_data\u001b[0m/\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# cd /drive\n", + "bash: cd: /drive: No such file or directory\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ] + } + ], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "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", + "execution_count": 6, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 303 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 46306, + "status": "ok", + "timestamp": 1581996455748, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "JGtw4BFzVU0Q", + "outputId": "9fbcb3a4-bf42-450b-8f6c-34568259e2bb" + }, + "outputs": [ + { + "name": "stdout", + "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@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# \n", + "\u001b]0;root@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# \n", + "\u001b]0;root@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# ll\n", + "total 20\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:23 \u001b[0m\u001b[01;34m.\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:18 \u001b[01;34m..\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 13 17:15 \u001b[01;34m.config\u001b[0m/\n", + "drwx------ 4 root root 4096 Feb 18 03:23 \u001b[01;34mdrive\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:37 \u001b[01;34msample_data\u001b[0m/\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# echo $SHELL\n", + "/bin/bash\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ] + } + ], + "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", + "execution_count": 10, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 128060, + "status": "ok", + "timestamp": 1581996716591, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "A16VzZ3G0J8x", + "outputId": "6eb3bd45-9e85-4c81-b5a4-b269495b6cc9" + }, + "outputs": [ + { + "name": "stdout", + "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@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\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@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n", + "\u001b]0;root@f39f7b993ac1: /content/drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd drive/My\\ Drive\n", + "bash: cd: drive/My Drive: No such file or directory\n", + "\u001b]0;root@f39f7b993ac1: /content/drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd /My\\ Drive\n", + "bash: cd: /My Drive: No such file or directory\n", + "\u001b]0;root@f39f7b993ac1: /content/drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# ll\n", + "total 20\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:23 \u001b[0m\u001b[01;34m.\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 18 03:18 \u001b[01;34m..\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 13 17:15 \u001b[01;34m.config\u001b[0m/\n", + "drwx------ 4 root root 4096 Feb 18 03:23 \u001b[01;34mdrive\u001b[0m/\n", + "drwxr-xr-x 1 root root 4096 Feb 5 18:37 \u001b[01;34msample_data\u001b[0m/\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n", + "\u001b]0;root@f39f7b993ac1: /content/drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd My\\ Drive\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# ll\n", + "total 57203\n", + "-rw------- 1 root root 26447 Aug 19 2017 010-CV_BRTC-Arif-2017.docx\n", + "-rw------- 1 root root 2112825 Mar 19 2017 \u001b[0m\u001b[01;35m20170317_112443.jpg\u001b[0m\n", + "-rw------- 1 root root 402342 Feb 21 2018 \u001b[01;35m20180221_110637.jpg\u001b[0m\n", + "-rw------- 1 root root 0 Dec 31 2017 6-15_math-bangla.pdf\n", + "-rw------- 1 root root 292640 Feb 19 2018 'Application Form.pdf'\n", + "drwx------ 2 root root 4096 Oct 18 2015 \u001b[01;34mApplication_USA\u001b[0m/\n", + "drwx------ 2 root root 4096 Oct 4 2015 \u001b[01;34m'Arif-M.Sc Presentation'\u001b[0m/\n", + "-rw------- 1 root root 70058 May 21 2016 'Arif_Pad (1).docx'\n", + "-rw------- 1 root root 70159 Jun 8 2016 Arif_Pad.docx\n", + "drwx------ 2 root root 4096 Oct 27 2016 \u001b[01;34m'Auto Call Recorder'\u001b[0m/\n", + "-rw------- 1 root root 119 Jul 9 2017 'BD map.gmap'\n", + "drwx------ 2 root root 4096 Oct 7 2017 \u001b[01;34mBirthday_Aishy\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 27 2017 \u001b[01;34mBRTC_Secretary\u001b[0m/\n", + "-rw------- 1 root root 16833 Nov 23 2015 \u001b[01;35mBUET.png\u001b[0m\n", + "drwx------ 2 root root 4096 Oct 8 2015 \u001b[01;34mBUGS_Secretary\u001b[0m/\n", + "drwx------ 2 root root 4096 Jul 4 2018 \u001b[01;34m'Car Ownership Transfer'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 11 2019 \u001b[01;34m'Colab Notebooks'\u001b[0m/\n", + "drwx------ 2 root root 4096 Oct 18 2015 \u001b[01;34mConvener\u001b[0m/\n", + "-rw------- 1 root root 3572943 Feb 9 2016 'CV_Academic_ Arif.pdf'\n", + "-rw------- 1 root root 63488 May 4 2017 CV_BRTC-Arif.doc\n", + "drwx------ 2 root root 4096 Feb 9 22:52 \u001b[01;34mData-1401-Repo\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 7 20:16 \u001b[01;34mData-1441\u001b[0m/\n", + "drwx------ 2 root root 4096 Jul 13 2016 \u001b[01;34mDelft3D_manuals\u001b[0m/\n", + "-rw------- 1 root root 25097 Nov 19 2017 document.pdf\n", + "-rw------- 1 root root 56815 Feb 6 2018 \u001b[01;35mdr-ferdousi-islam-lipi_70_1.jpg\u001b[0m\n", + "drwx------ 2 root root 4096 Jun 4 2017 \u001b[01;34m'Duncan Brothers Ltd'\u001b[0m/\n", + "drwx------ 2 root root 4096 May 9 2016 \u001b[01;34m'Earthquake Assignment'\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 24 2015 \u001b[01;34mEbook\u001b[0m/\n", + "drwx------ 2 root root 4096 Jul 16 2016 \u001b[01;34mE_Flow_Gorai\u001b[0m/\n", + "drwx------ 2 root root 4096 Jul 24 2017 \u001b[01;34m'Ehsan Vai'\u001b[0m/\n", + "drwx------ 2 root root 4096 Apr 3 2018 \u001b[01;34mEnglish_Learning\u001b[0m/\n", + "-rw------- 1 root root 173322 Aug 18 2016 excel.pdf\n", + "-rw------- 1 root root 88915 Aug 2 2017 ex_routine_final.pdf\n", + "-rw------- 1 root root 64000 Mar 28 2017 Final_List_of_Group_A_House_05.02.2017.xls\n", + "-rw------- 1 root root 2535936 Nov 22 2017 Flow_Duration_Tutorial_DL_File.xls\n", + "-rw------- 1 root root 9834856 Apr 27 2016 folder-lock-en.exe\n", + "drwx------ 2 root root 4096 Oct 5 2016 \u001b[01;34m'For Sheola Hydrology expert'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 6 2017 \u001b[01;34m'From Dropbox'\u001b[0m/\n", + "drwx------ 2 root root 4096 Sep 4 2016 \u001b[01;34mGeoSWMM\u001b[0m/\n", + "drwx------ 2 root root 4096 Jun 10 2015 \u001b[01;34mGIS\u001b[0m/\n", + "drwx------ 2 root root 4096 Sep 17 2016 \u001b[01;34m'Google Photos'\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 11 2017 \u001b[01;34m'GPS Data Extraction'\u001b[0m/\n", + "-rw------- 1 root root 53172 Aug 22 2016 Grade_Sheet_Preparation.xlsx\n", + "drwx------ 2 root root 4096 Sep 18 2015 \u001b[01;34mGRE_Triumph\u001b[0m/\n", + "drwx------ 2 root root 4096 May 27 2018 \u001b[01;34mHEC-Soft\u001b[0m/\n", + "drwx------ 2 root root 4096 Oct 8 2015 \u001b[01;34mHEQEP\u001b[0m/\n", + "-rw------- 1 root root 182434 Jan 21 2017 house_allotment_A.pdf\n", + "-rw------- 1 root root 18326 Oct 30 2017 'Invitation List for Marriage Ceremony.docx'\n", + "-rw------- 1 root root 30464 Nov 1 2016 Item_Nuffic_PnD.docx\n", + "drwx------ 2 root root 4096 Jun 14 2015 \u001b[01;34m'January 15 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Mar 1 2016 \u001b[01;34m'January 16 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Jan 29 2017 \u001b[01;34m'January 17 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 24 2018 \u001b[01;34m'January 18 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Apr 29 2017 \u001b[01;34mJFCL\u001b[0m/\n", + "drwx------ 2 root root 4096 Apr 22 2017 \u001b[01;34mJFCL_Visit\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 23 2016 \u001b[01;34m'July 14 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Jan 31 2016 \u001b[01;34m'July 15 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 May 21 2016 \u001b[01;34m'July 16 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 24 2018 \u001b[01;34m'July 17 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 5 2018 \u001b[01;34m'July 18 Term'\u001b[0m/\n", + "drwx------ 2 root root 4096 Jul 20 2016 \u001b[01;34mKaharole_Bridge\u001b[0m/\n", + "drwx------ 2 root root 4096 May 14 2017 \u001b[01;34m'Lab Sheet'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 19 2016 \u001b[01;34m'Learn Excel'\u001b[0m/\n", + "-rw------- 1 root root 0 Dec 4 07:08 LinearScalingBiasCorrectionV.1.0.xlsx\n", + "-rw------- 1 root root 545663 Nov 8 2015 MAC_Collect_Notice.pdf\n", + "-rw------- 1 root root 579502 Jul 24 2017 Map.docx\n", + "drwx------ 2 root root 4096 Sep 19 2018 \u001b[01;34m'Matagorda_HMS Model'\u001b[0m/\n", + "-rw------- 1 root root 20181 Jul 16 2016 'Meal Calculation Arifur Rahman (July 1-15) 2016.xlsx'\n", + "-rw------- 1 root root 1118820 Feb 15 2017 Minutes_BUGS_WRE_BUET.pdf\n", + "-rw------- 1 root root 39897 Apr 10 2017 'MSc admission April 2017 Semester (Equivalence).xlsx'\n", + "-rw------- 1 root root 20192 Apr 10 2017 'M.Sc. Engg. Admission April 2017 (Degree Equivalence).docx'\n", + "-rw------- 1 root root 464450 Jan 27 2018 M.Sc_WRE_6501.pdf\n", + "drwx------ 2 root root 4096 Apr 19 2016 \u001b[01;34mMuhuri\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 10 2016 \u001b[01;34mNafi_data\u001b[0m/\n", + "-rw------- 1 root root 373818 Jan 26 2017 NID.docx\n", + "-rw------- 1 root root 3417722 Oct 17 2016 \u001b[01;35mNID.jpg\u001b[0m\n", + "-rw------- 1 root root 135140 Jan 26 2017 NID.pdf\n", + "drwx------ 2 root root 4096 Dec 20 2015 \u001b[01;34mNSU\u001b[0m/\n", + "drwx------ 2 root root 4096 Dec 3 2017 \u001b[01;34mNuffic_\u001b[0m/\n", + "drwx------ 2 root root 4096 Jun 27 2016 \u001b[01;34mNuffic_155\u001b[0m/\n", + "-rw------- 1 root root 254095 Jul 16 2016 pad.wre.docx\n", + "-rw------- 1 root root 242706 Dec 17 2015 'Pay_Scale For Public_Univ.Treachers.pdf'\n", + "-rw------- 1 root root 13096992 Jul 17 2016 \u001b[01;31mPHSetup.zip\u001b[0m\n", + "drwx------ 2 root root 4096 Jun 11 2018 \u001b[01;34mpython-3.6.5-docs-pdf-letter\u001b[0m/\n", + "-rw------- 1 root root 68608 May 27 2015 'Question Format.doc'\n", + "-rw------- 1 root root 24147 May 21 2016 'Question Format.docx'\n", + "drwx------ 2 root root 4096 Nov 17 2015 \u001b[01;34m'Recommendations for Students'\u001b[0m/\n", + "-rw------- 1 root root 255452 Jul 26 2017 'Request_Recommendation(2).pdf'\n", + "-rw------- 1 root root 159108 Nov 9 2016 Resume-of-Arif.pdf\n", + "-rw------- 1 root root 380114 Jul 25 2017 'Resume of Md Arifur Rahman.pdf'\n", + "drwx------ 2 root root 4096 Jun 25 2018 \u001b[01;34mR-Studio\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 7 2017 \u001b[01;34mSandwip\u001b[0m/\n", + "drwx------ 2 root root 4096 May 2 2016 \u001b[01;34mSonagaon\u001b[0m/\n", + "-rw------- 1 root root 1112890 Aug 12 2018 Statistical_Methods.docx\n", + "-rw------- 1 root root 15287341 Aug 12 2018 \u001b[01;31mStatistical-Methods-in-Hydrology-C-T-HaaN.zip\u001b[0m\n", + "-rw------- 1 root root 58549 Aug 26 2017 StudentGradeSheet.pdf\n", + "drwx------ 2 root root 4096 Oct 7 2016 \u001b[01;34mSWAT_DATA\u001b[0m/\n", + "-rw------- 1 root root 153042 Dec 29 2015 Syllabus_WRE.pdf\n", + "drwx------ 2 root root 4096 Sep 20 2015 \u001b[01;34mTAX-2015-2016\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 19 2017 \u001b[01;34mTOEFL_Triumph\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 1 2016 \u001b[01;34mUGC\u001b[0m/\n", + "-rw------- 1 root root 177544 Aug 18 2016 Uni_Teacher_Uniform_Upgradation_Rules_Drafted_by_UGC.pdf\n", + "dr-x------ 2 root root 4096 Jun 7 2018 \u001b[01;34m'US Visa 2018'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 28 2018 \u001b[01;34m'UTA_Fall 2018'\u001b[0m/\n", + "drwx------ 2 root root 4096 Jan 20 2016 \u001b[01;34mVideo\u001b[0m/\n", + "drwx------ 2 root root 4096 Sep 19 2016 \u001b[01;34mWallpapers\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 12 2018 \u001b[01;34mWedding_Photos_Vedios\u001b[0m/\n", + "drwx------ 2 root root 4096 Oct 4 2017 \u001b[01;34m'Wedding Sweety'\u001b[0m/\n", + "drwx------ 2 root root 4096 Nov 28 2017 \u001b[01;34m'WRE 404- Excersizes'\u001b[0m/\n", + "drwx------ 2 root root 4096 May 27 2015 \u001b[01;34m'WRE 428_GIS'\u001b[0m/\n", + "drwx------ 2 root root 4096 Aug 1 2016 \u001b[01;34mWRE_Curriculum\u001b[0m/\n", + "drwx------ 2 root root 4096 Apr 24 2016 \u001b[01;34mWrite-up\u001b[0m/\n", + "-rw------- 1 root root 136952 May 24 2018 \u001b[01;35m'www (1).weddingdiary.bd.com190-1.jpg'\u001b[0m\n", + "-rw------- 1 root root 472345 Jun 9 2018 \u001b[01;35mwww.weddingdiary.bd.com190-1.jpg\u001b[0m\n", + "drwx------ 2 root root 4096 Jul 18 2016 \u001b[01;34mX-sections_Data\u001b[0m/\n", + "drwx------ 2 root root 4096 Feb 19 2017 \u001b[01;34mX-Trail\u001b[0m/\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1441/\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mLab-1-Solutions\u001b[0m\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive/Data-1441\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441\u001b[00m# cd Lab-1-Solutions\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# ll\n", + "total 0\n", + "\u001b]0;root@f39f7b993ac1: /content/drive/My Drive/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1441/Lab-1-Solutions\u001b[00m# exit\n", + "exit\n" + ] + } + ], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "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", + "execution_count": 12, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 624 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 87014, + "status": "ok", + "timestamp": 1581997019652, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "yNj2LXzP2ksl", + "outputId": "24b13a69-b461-4ead-d8e5-dbe873ec3897" + }, + "outputs": [ + { + "name": "stdout", + "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@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mbin\u001b[0m \u001b[01;34metc\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34msys\u001b[0m\n", + "\u001b[01;34mboot\u001b[0m \u001b[01;34mhome\u001b[0m \u001b[01;34mproc\u001b[0m \u001b[01;34mtensorflow-2.1.0\u001b[0m\n", + "\u001b[01;34mcontent\u001b[0m \u001b[01;34mlib\u001b[0m \u001b[01;34mroot\u001b[0m \u001b[30;42mtmp\u001b[0m\n", + "\u001b[01;34mdatalab\u001b[0m \u001b[01;34mlib32\u001b[0m \u001b[01;34mrun\u001b[0m \u001b[01;34mtools\u001b[0m\n", + "\u001b[01;34mdev\u001b[0m \u001b[01;34mlib64\u001b[0m \u001b[01;34msbin\u001b[0m \u001b[01;34musr\u001b[0m\n", + "dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl \u001b[01;34mmedia\u001b[0m \u001b[01;34msrv\u001b[0m \u001b[01;34mvar\u001b[0m\n", + "dlib-19.18.0-cp36-cp36m-linux_x86_64.whl \u001b[01;34mmnt\u001b[0m \u001b[01;34mswift\u001b[0m\n", + "\u001b]0;root@f39f7b993ac1: /\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/\u001b[00m# cd dev\n", + "\u001b]0;root@f39f7b993ac1: /dev\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/dev\u001b[00m# ls\n", + "\u001b[0m\u001b[01;36mcore\u001b[0m \u001b[40;33;01mfull\u001b[0m \u001b[30;42mmqueue\u001b[0m \u001b[01;36mptmx\u001b[0m \u001b[40;33;01mrandom\u001b[0m \u001b[01;36mstderr\u001b[0m \u001b[01;36mstdout\u001b[0m \u001b[40;33;01murandom\u001b[0m\n", + "\u001b[01;36mfd\u001b[0m \u001b[40;33;01mfuse\u001b[0m \u001b[40;33;01mnull\u001b[0m \u001b[01;34mpts\u001b[0m \u001b[30;42mshm\u001b[0m \u001b[01;36mstdin\u001b[0m \u001b[40;33;01mtty\u001b[0m \u001b[40;33;01mzero\u001b[0m\n", + "\u001b]0;root@f39f7b993ac1: /dev\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/dev\u001b[00m# sudo lsblk -o NAME,FSTYPE,SIZE,MOUNTPOINT,LABEL\n", + "NAME FSTYPE SIZE MOUNTPOINT LABEL\n", + "loop0 110G \n", + "sda 120G \n", + "├─sda1 115.9G /etc/hosts \n", + "├─sda2 16M \n", + "├─sda3 2G \n", + "├─sda4 16M \n", + "├─sda5 2G \n", + "├─sda6 512B \n", + "├─sda7 512B \n", + "├─sda8 16M \n", + "├─sda9 512B \n", + "├─sda10 512B \n", + "├─sda11 8M \n", + "└─sda12 32M \n", + "\u001b]0;root@f39f7b993ac1: /dev\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/dev\u001b[00m# exit\n", + "exit\n" + ] + } + ], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "e13qAhN3XuB2" + }, + "outputs": [], + "source": [ + "There is only SSD present and it has 12 partitions " + ] + }, + { + "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", + "execution_count": 15, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "colab_type": "code", + "executionInfo": { + "elapsed": 54592, + "status": "ok", + "timestamp": 1581998641086, + "user": { + "displayName": "Md Arifur Rahmahn", + "photoUrl": "https://lh3.googleusercontent.com/a-/AAuE7mCuQO1LRnE670SeuMljmw_gfOSqyXgeoMUW8t8MnrU=s64", + "userId": "10793096758468142333" + }, + "user_tz": 360 + }, + "id": "UlsANMuf2qMs", + "outputId": "382d8c2d-c7c5-4c93-bfd3-3b1bb12d6dd9" + }, + "outputs": [ + { + "name": "stdout", + "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@f39f7b993ac1: /content/sample_data\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /content\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/content\u001b[00m# cd ..\n", + "\u001b]0;root@f39f7b993ac1: /\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mbin\u001b[0m \u001b[01;34metc\u001b[0m \u001b[01;34mopt\u001b[0m \u001b[01;34msys\u001b[0m\n", + "\u001b[01;34mboot\u001b[0m \u001b[01;34mhome\u001b[0m \u001b[01;34mproc\u001b[0m \u001b[01;34mtensorflow-2.1.0\u001b[0m\n", + "\u001b[01;34mcontent\u001b[0m \u001b[01;34mlib\u001b[0m \u001b[01;34mroot\u001b[0m \u001b[30;42mtmp\u001b[0m\n", + "\u001b[01;34mdatalab\u001b[0m \u001b[01;34mlib32\u001b[0m \u001b[01;34mrun\u001b[0m \u001b[01;34mtools\u001b[0m\n", + "\u001b[01;34mdev\u001b[0m \u001b[01;34mlib64\u001b[0m \u001b[01;34msbin\u001b[0m \u001b[01;34musr\u001b[0m\n", + "dlib-19.18.0-cp27-cp27mu-linux_x86_64.whl \u001b[01;34mmedia\u001b[0m \u001b[01;34msrv\u001b[0m \u001b[01;34mvar\u001b[0m\n", + "dlib-19.18.0-cp36-cp36m-linux_x86_64.whl \u001b[01;34mmnt\u001b[0m \u001b[01;34mswift\u001b[0m\n", + "\u001b]0;root@f39f7b993ac1: /\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/\u001b[00m# cd etc\n", + "\u001b]0;root@f39f7b993ac1: /etc\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/etc\u001b[00m# ls\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@f39f7b993ac1: /etc\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/etc\u001b[00m# cat 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@f39f7b993ac1: /etc\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/etc\u001b[00m# wc passwd\n", + " 23 33 1243 passwd\n", + "\u001b]0;root@f39f7b993ac1: /etc\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/etc\u001b[00m# grep -c \"w\" /etc/passwd\n", + "3\n", + "\u001b]0;root@f39f7b993ac1: /etc\u0007\u001b[01;32mroot@f39f7b993ac1\u001b[00m:\u001b[01;34m/etc\u001b[00m# exit\n", + "exit\n" + ] + } + ], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ze-vqoBfdjRv" + }, + "outputs": [], + "source": [ + "There are 3 lines that contains letter \"w\"." + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "4a8wSbrqgtiY" + }, + "outputs": [], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "oP9XlZl_3iZD" + }, + "outputs": [], + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "e5tXg0f8qv0D" + }, + "outputs": [], + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "WYsyYcg1qv0J" + }, + "source": [ + "Make a new directory:" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Z7noY1hMqv0L" + }, + "outputs": [], + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "8w42MH6Jqv0S" + }, + "outputs": [], + "source": [ + "# What you past here should look like:\n", + "#!git clone https://github.com//DATA1401-Spring-2020.git" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "cOAuqTVUqv0V" + }, + "source": [ + "Go into the directory:" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "b1Ew4tEZqv0X" + }, + "outputs": [], + "source": [ + "%cd DATA1401-Spring-2020\n", + "!ls" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "JxtMYR-9qv0c" + }, + "outputs": [], + "source": [ + "!git remote -v" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "9ud3X0fBqv0f" + }, + "source": [ + "Now use the original class URL to set your upstream:" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "pgJlKxBqqv0h" + }, + "outputs": [], + "source": [ + "!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "id2yUEt9qv0k" + }, + "outputs": [], + "source": [ + "!git remote -v" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AGDsfTFLqv0o" + }, + "outputs": [], + "source": [ + "!git pull" + ] + }, + { + "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", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "PPfGmFQI40HR" + }, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "collapsed_sections": [], + "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": 1581996073993 + } + ] + }, + "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 +} From c2b5096e211d1eaca7d5dedd0e48e1047cb1215b Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 28 Feb 2020 12:02:34 -0600 Subject: [PATCH 05/12] Add files via upload Md Arifur Rahman, UTA ID: 1001618032 --- Labs/Lab-3/Lab-3-Submission.ipynb | 1397 +++++++++++++++++++++++++++++ 1 file changed, 1397 insertions(+) create mode 100644 Labs/Lab-3/Lab-3-Submission.ipynb diff --git a/Labs/Lab-3/Lab-3-Submission.ipynb b/Labs/Lab-3/Lab-3-Submission.ipynb new file mode 100644 index 0000000..b3769ac --- /dev/null +++ b/Labs/Lab-3/Lab-3-Submission.ipynb @@ -0,0 +1,1397 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ma6clCnfJ4Dj" + }, + "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": "Uhe_Vb2SJ4Dr" + }, + "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": 391, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "eDNc3n1UJ4Dv" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Enter the size of the board\n", + "5\n" + ] + }, + { + "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": 391, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Write you solution here\n", + "player_1 = 1\n", + "player_2 = 2\n", + "empty = 0\n", + "player_1_piece=\"X\"\n", + "player_2_piece=\"O\"\n", + "empty_space=\" \"\n", + "print(\"Enter the size of the board\")\n", + "size = int(input())\n", + "def tic_tac_toe_board(size):\n", + " board = [[empty]*size for i in range(size)]\n", + " return board\n", + "tic_tac_toe_board(size)" + ] + }, + { + "cell_type": "code", + "execution_count": 392, + "metadata": {}, + "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": 392, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "#tic_tac_toe_board(3)\n", + "#tic_tac_toe_board(4)\n", + "gboard=tic_tac_toe_board(5)\n", + "#print(tic_tac_toe_board(6))\n", + "gboard" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "T4kfpTb4J4EJ" + }, + "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": 393, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "mcpYwoPsJ4EM" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "import numpy as np\n", + "\n", + "def checkRows(board):\n", + " for row in board:\n", + " if len(set(row)) == 1:\n", + " return row[0]\n", + " return 0\n", + "\n", + "def checkDiagonals(board):\n", + " if len(set([board[i][i] for i in range(len(board))])) == 1:\n", + " return board[0][0]\n", + " if len(set([board[i][len(board)-i-1] for i in range(len(board))])) == 1:\n", + " return board[0][len(board)-1]\n", + " return 0\n", + "\n", + "def checkIsWin(board):\n", + " #transposition to check rows, then columns\n", + " for newBoard in [board, np.transpose(board)]:\n", + " result = checkRows(newBoard)\n", + " if result:\n", + " return result\n", + " return checkDiagonals(board)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 394, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ofKfwqunJ4EV" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "1\n", + "2\n", + "0\n", + "0\n", + "1\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "\n", + "winner_is_2 =[[2, 2, 0,0],\n", + " [2, 1, 0,1],\n", + " [2, 1, 1,2],\n", + " [2, 1, 1,0]]\n", + "\n", + "winner_is_1 =[[1, 2, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 1]]\n", + "\n", + "winner_is_also_1 =[[0, 1, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 1]]\n", + "\n", + "no_winner =[[1, 2, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 2]]\n", + "\n", + "also_no_winner =[[1, 2, 0],\n", + " [2, 1, 0],\n", + " [2, 1, 0]]\n", + "\n", + "board_5X5 =[[1, 2, 0,0,1],\n", + " [0, 1, 0,1,2],\n", + " [2, 1, 1,2,0],\n", + " [2, 1, 1,1,2],\n", + " [2, 1, 1,0,1]]\n", + "\n", + "print(checkIsWin(winner_is_1))\n", + "print(checkIsWin(winner_is_also_1))\n", + "print(checkIsWin(winner_is_2))\n", + "print(checkIsWin(no_winner))\n", + "print(checkIsWin(also_no_winner))\n", + "print(checkIsWin(board_5X5))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "UK3wvAPLJ4El" + }, + "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": 395, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "j8Z21YiQJ4Eo" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " --- --- --- --- --- \n", + "| | | | | | \n", + " --- --- --- --- --- \n", + "| | | | | | \n", + " --- --- --- --- --- \n", + "| | | | | | \n", + " --- --- --- --- --- \n", + "| | | | | | \n", + " --- --- --- --- --- \n", + "| | | | | | \n", + " --- --- --- --- --- \n" + ] + } + ], + "source": [ + "# Write you solution here\n", + "def draw_game_board(size): \n", + " i = 0\n", + " h = \" --- \"\n", + " v = \"| \"\n", + " h = h * size\n", + " v = v * (size+1)\n", + " while i < size+1:\n", + " print (h)\n", + " if not (i == size):\n", + " print (v)\n", + " i += 1\n", + "board=draw_game_board(size)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 396, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "mC2qENzHJ4Ex" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n", + "| | | | | | | \n", + " --- --- --- --- --- --- \n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "#draw_game_board(3)\n", + "#draw_game_board(4)\n", + "draw_game_board(6)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "NE16SLTUJ4E5" + }, + "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": 397, + "metadata": {}, + "outputs": [], + "source": [ + "# Write you solution here\n", + "\n", + "def Tic_Tac_Toe_board(board):\n", + " for i in range(len(board)):\n", + " for j in range(len(board[i])):\n", + " if board[i][j] == 1:\n", + " board[i][j]=player_1_piece\n", + " elif board[i][j] == 2:\n", + " board[i][j]=player_2_piece\n", + " else:\n", + " board[i][j]=empty_space\n", + " \n", + " for row in board:\n", + " print(''.join([f\"| {element} \" for element in row]))\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 398, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "| X | O | | | X \n", + "| | X | | X | O \n", + "| O | X | X | O | \n", + "| O | X | X | X | O \n", + "| O | X | X | | X \n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "\n", + "Tic_Tac_Toe_board(board_5X5) " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "WbXLA9fAJ4FL" + }, + "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": 399, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "hHLW_m__J4FO" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "\n", + "def place_piece(board,player,coordinate,verbose=True):\n", + " x,y = coordinate\n", + " \n", + " # Check if player's piece is at location\n", + " if not board[x][y]==player:\n", + " print(f\"player does not have piece at {coordinate}\", \"location.\",verbose)\n", + " #return False\n", + " if board[x][y]==empty:\n", + " board[x][y]=player\n", + " print(f\"Successfully Placed Player {player}!\",verbose)\n", + " return True\n", + " if not board[x][y]==empty:\n", + " print(\"Move not possible coz the place is already occupied other by player\")\n", + " return False\n", + " else:\n", + " print(f\"Move not possible coz the place is already occupied by player {player}\")\n", + " return False\n" + ] + }, + { + "cell_type": "code", + "execution_count": 415, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "player does not have piece at (0, 2) location. True\n", + "Successfully Placed Player 1! True\n" + ] + }, + { + "data": { + "text/plain": [ + "[[1, 2, 1, 0, 1],\n", + " [0, 1, 0, 1, 2],\n", + " [2, 1, 1, 2, 0],\n", + " [2, 1, 1, 1, 2],\n", + " [2, 1, 1, 0, 1]]" + ] + }, + "execution_count": 415, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "board_5X5 =[[1, 2, 0,0,1],\n", + " [0, 1, 0,1,2],\n", + " [2, 1, 1,2,0],\n", + " [2, 1, 1,1,2],\n", + " [2, 1, 1,0,1]]\n", + "\n", + "place_piece(board_5X5,player_1,(0,2))\n", + "gameboard" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "nU8pP2PCJ4Fb" + }, + "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": 401, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ZsieEzORJ4Fd" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "\n", + "def draw_nice_board(board):\n", + " row_names=list(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n", + " row_map=dict(zip(row_names,range(len(board))))\n", + " column_names=list(map(str,range(1,len(board)+1)))\n", + " column_map=dict(zip(column_names,range(len(board))))\n", + "\n", + " space_character= { player_1: player_1_piece,\n", + " player_2: player_2_piece,\n", + " empty: empty_space }\n", + " \n", + " print(\" \",end=\" \")\n", + " for j in range(len(board)):\n", + " print(column_names[j],end=\" \")\n", + " print()\n", + " for i in range(len(board)):\n", + " print(row_names[i],end=\" \")\n", + " for j in range(len(board)):\n", + " print(space_character[board[i][j]],end=\" \")\n", + " print()" + ] + }, + { + "cell_type": "code", + "execution_count": 403, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 1 2 3 4 5 \n", + "A X O X \n", + "B X X O \n", + "C O X X O \n", + "D O X X X O \n", + "E O X X X \n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "newboard =[[1, 2, 0,0,1],\n", + " [0, 1, 0,1,2],\n", + " [2, 1, 1,2,0],\n", + " [2, 1, 1,1,2],\n", + " [2, 1, 1,0,1]]\n", + "draw_nice_board(newboard)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "jL3YbD09J4Fr" + }, + "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": 404, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "aQmKiaFmJ4Fu" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "def print_message(message,verbose=True):\n", + " if verbose:\n", + " print(message)\n", + " \n", + "\n", + "def specified_location(l_string):\n", + " if not isinstance(l_string,str):\n", + " print_message(\"Bad Input. Location must be string.\")\n", + " return False\n", + " \n", + " if len(l_string)!=2:\n", + " print_message(\"Bad Input. Location must be 2 characters.\")\n", + " return False\n", + " \n", + " row=l_string[0].upper()\n", + " col=l_string[1].upper()\n", + " \n", + " if not row in row_names:\n", + " print_message(\"Bad Row.\")\n", + " return False\n", + "\n", + " if not col in column_names:\n", + " print_message(\"Bad Column.\")\n", + " return False\n", + "\n", + " return row_map[row],column_map[col]\n", + "\n", + "def nice_placing_piece(board,player,location):\n", + " loc=specified_location(location)\n", + " #mov=parse_move(move)\n", + "\n", + " if loc !=-1:\n", + " return place_piece(board,player,loc)\n", + " else:\n", + " return print_message(\"Bad placing.\")" + ] + }, + { + "cell_type": "code", + "execution_count": 406, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "dOZfOL_SJ4Fz" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 1 2 3 4 5 \n", + "A X O X \n", + "B X X O \n", + "C O X X O \n", + "D O X X X O \n", + "E O X X X \n", + "player does not have piece at (2, 4) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X O X \n", + "B X X O \n", + "C O X X O X \n", + "D O X X X O \n", + "E O X X X \n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "draw_nice_board(newboard)\n", + "nice_placing_piece(newboard,player_1,\"C5\")\n", + "draw_nice_board(newboard)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 408, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 1 2 3 4 5 \n", + "A X O O X \n", + "B X X O \n", + "C O X X O X \n", + "D O X X X O \n", + "E O X X X \n", + "player does not have piece at (0, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O O O X \n", + "B X X O \n", + "C O X X O X \n", + "D O X X X O \n", + "E O X X X \n" + ] + } + ], + "source": [ + "draw_nice_board(newboard)\n", + "nice_placing_piece(newboard,player_2,\"A3\")\n", + "draw_nice_board(newboard)\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "UPhJrxV5J4F4" + }, + "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": 409, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Hi1MO3I5J4F7" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "def take_place(board,player):\n", + " good_place=False\n", + " \n", + " while not good_place:\n", + " loc_str =input(\"Enter your location:\")\n", + " \n", + " good_place = nice_placing_piece(board,player,loc_str)" + ] + }, + { + "cell_type": "code", + "execution_count": 410, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "-Za9PvDAJ4GA" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 1 2 3 4 5 \n", + "A X O O O X \n", + "B X X O \n", + "C O X X O X \n", + "D O X X X O \n", + "E O X X X \n", + "Enter your location:b1\n", + "player does not have piece at (1, 0) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O O O X \n", + "B O X X O \n", + "C O X X O X \n", + "D O X X X O \n", + "E O X X X \n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "draw_nice_board(newboard)\n", + "take_place(newboard,player_2)\n", + "draw_nice_board(newboard)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h5DrjSARJ4GG" + }, + "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": 411, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "rT3toqvJJ4GJ" + }, + "outputs": [], + "source": [ + "# Write you solution here\n", + "def Tic_Tac_Toe():\n", + " \n", + " print (\"Welcome to Tic Tac Toe Game.\")\n", + " print (\"----------------------------\")\n", + " size = int(input(\"Enter the size of the game board \"))\n", + "\n", + " # Make a game board\n", + " board_0=tic_tac_toe_board(size)\n", + " \n", + " # Start with player 1=\"X\"\n", + " player=player_1\n", + " \n", + " this_game_won=False\n", + " while not this_game_won:\n", + " # Draw the board\n", + " draw_nice_board(board_0)\n", + " \n", + " # Take a place\n", + " print (\"Player\",player,\"place:\")\n", + " take_place(board_0,player)\n", + "\n", + " # Check if the game has been won\n", + " this_game_won=checkIsWin(board_0)\n", + "\n", + " # Switch players\n", + " if player==player_1:\n", + " player=player_2\n", + " else:\n", + " player=player_1\n", + " \n", + " draw_nice_board(board_0) \n", + " print(\"Winner is player:\",this_game_won, \"Congratulations!!\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 412, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "wa1ZYp1BJ4GO" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to Tic Tac Toe Game.\n", + "----------------------------\n", + "Enter the size of the game board 3\n", + " 1 2 3 \n", + "A \n", + "B \n", + "C \n", + "Player 1 place:\n", + "Enter your location:a1\n", + "player does not have piece at (0, 0) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 \n", + "A X \n", + "B \n", + "C \n", + "Player 2 place:\n", + "Enter your location:b3\n", + "player does not have piece at (1, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 \n", + "A X \n", + "B O \n", + "C \n", + "Player 1 place:\n", + "Enter your location:b2\n", + "player does not have piece at (1, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 \n", + "A X \n", + "B X O \n", + "C \n", + "Player 2 place:\n", + "Enter your location:c1\n", + "player does not have piece at (2, 0) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 \n", + "A X \n", + "B X O \n", + "C O \n", + "Player 1 place:\n", + "Enter your location:c3\n", + "player does not have piece at (2, 2) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 \n", + "A X \n", + "B X O \n", + "C O X \n", + "Winner is player: 1 Congratulations!!\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "Tic_Tac_Toe()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "kyDby7JdJ4GT" + }, + "source": [ + "*Exercise 10:* Test that your game works for 5x5 Tic Tac Toe. " + ] + }, + { + "cell_type": "code", + "execution_count": 414, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "sueLdBPRJ4GV" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to Tic Tac Toe Game.\n", + "----------------------------\n", + "Enter the size of the game board 5\n", + " 1 2 3 4 5 \n", + "A \n", + "B \n", + "C \n", + "D \n", + "E \n", + "Player 1 place:\n", + "Enter your location:a1\n", + "player does not have piece at (0, 0) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B \n", + "C \n", + "D \n", + "E \n", + "Player 2 place:\n", + "Enter your location:b3\n", + "player does not have piece at (1, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B O \n", + "C \n", + "D \n", + "E \n", + "Player 1 place:\n", + "Enter your location:c2\n", + "player does not have piece at (2, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B O \n", + "C X \n", + "D \n", + "E \n", + "Player 2 place:\n", + "Enter your location:e1\n", + "player does not have piece at (4, 0) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B O \n", + "C X \n", + "D \n", + "E O \n", + "Player 1 place:\n", + "Enter your location:b2\n", + "player does not have piece at (1, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B X O \n", + "C X \n", + "D \n", + "E O \n", + "Player 2 place:\n", + "Enter your location:d3\n", + "player does not have piece at (3, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B X O \n", + "C X \n", + "D O \n", + "E O \n", + "Player 1 place:\n", + "Enter your location:c1\n", + "player does not have piece at (2, 0) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X \n", + "B X O \n", + "C X X \n", + "D O \n", + "E O \n", + "Player 2 place:\n", + "Enter your location:a5\n", + "player does not have piece at (0, 4) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O \n", + "B X O \n", + "C X X \n", + "D O \n", + "E O \n", + "Player 1 place:\n", + "Enter your location:e5\n", + "player does not have piece at (4, 4) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X O \n", + "B X O \n", + "C X X \n", + "D O \n", + "E O X \n", + "Player 2 place:\n", + "Enter your location:b4\n", + "player does not have piece at (1, 3) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O \n", + "B X O O \n", + "C X X \n", + "D O \n", + "E O X \n", + "Player 1 place:\n", + "Enter your location:d2\n", + "player does not have piece at (3, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X O \n", + "B X O O \n", + "C X X \n", + "D X O \n", + "E O X \n", + "Player 2 place:\n", + "Enter your location:a3\n", + "player does not have piece at (0, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O O \n", + "B X O O \n", + "C X X \n", + "D X O \n", + "E O X \n", + "Player 1 place:\n", + "Enter your location:c4\n", + "player does not have piece at (2, 3) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X O O \n", + "B X O O \n", + "C X X X \n", + "D X O \n", + "E O X \n", + "Player 2 place:\n", + "Enter your location:c3\n", + "player does not have piece at (2, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O O \n", + "B X O O \n", + "C X X O X \n", + "D X O \n", + "E O X \n", + "Player 1 place:\n", + "Enter your location:e2\n", + "player does not have piece at (4, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 4 5 \n", + "A X O O \n", + "B X O O \n", + "C X X O X \n", + "D X O \n", + "E O X X \n", + "Player 2 place:\n", + "Enter your location:e3\n", + "player does not have piece at (4, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 4 5 \n", + "A X O O \n", + "B X O O \n", + "C X X O X \n", + "D X O \n", + "E O X O X \n", + "Winner is player: 2 Congratulations!!\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "Tic_Tac_Toe()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "olA3sZVDJ4Ga" + }, + "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": 418, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "LXRZ7ndjJ4Gb" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to Tic Tac Toe!\n", + "Do you want to be X or O?\n", + "x\n", + "The player will go first.\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " | | \n", + " | |\n", + "What is your next move? (1-9)\n", + "2\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " | X | O\n", + " | |\n", + "What is your next move? (1-9)\n", + "6\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " | | X\n", + " | |\n", + "-----------\n", + " | |\n", + " O | X | O\n", + " | |\n", + "What is your next move? (1-9)\n", + "6\n", + "What is your next move? (1-9)\n", + "1\n", + "What is your next move? (1-9)\n", + "\n", + "What is your next move? (1-9)\n", + "5\n", + " | |\n", + " | | \n", + " | |\n", + "-----------\n", + " | |\n", + " O | X | X\n", + " | |\n", + "-----------\n", + " | |\n", + " O | X | O\n", + " | |\n", + "What is your next move? (1-9)\n", + "8\n", + " | |\n", + " | X | \n", + " | |\n", + "-----------\n", + " | |\n", + " O | X | X\n", + " | |\n", + "-----------\n", + " | |\n", + " O | X | O\n", + " | |\n", + "Hooray! You have won the game!\n", + "Do you want to play again? (yes or no)\n", + "no\n" + ] + } + ], + "source": [ + "# Write you solution here\n", + " # Tic Tac Toe for 3x3 game board\n", + "\n", + "import random\n", + "\n", + "def drawBoard(board):\n", + "\n", + "# This function prints out the board that it was passed.\n", + "\n", + "# \"board\" is a list of 10 strings representing the board (ignore index 0)\n", + "\n", + " print(' | |')\n", + "\n", + " print(' ' + board[7] + ' | ' + board[8] + ' | ' + board[9])\n", + "\n", + " print(' | |')\n", + "\n", + " print('-----------')\n", + "\n", + " print(' | |')\n", + "\n", + " print(' ' + board[4] + ' | ' + board[5] + ' | ' + board[6])\n", + "\n", + " print(' | |')\n", + "\n", + " print('-----------')\n", + "\n", + " print(' | |')\n", + "\n", + " print(' ' + board[1] + ' | ' + board[2] + ' | ' + board[3])\n", + "\n", + " print(' | |')\n", + "\n", + "\n", + "def inputPlayerLetter():\n", + " \n", + " letter = ''\n", + "\n", + "# Lets the player type which letter they want to be.\n", + "\n", + "# Returns a list with the player’s letter as the first item, and the computer's letter as the second.\n", + "\n", + " while not (letter == 'X' or letter == 'O'):\n", + " print('Do you want to be X or O?')\n", + " letter = input().upper()\n", + "\n", + "# the first element in the list is the player’s letter, the second is the computer's letter.\n", + "\n", + " if letter == 'X':\n", + " return ['X', 'O']\n", + "\n", + " else:\n", + " return ['O', 'X']\n", + "\n", + "def whoGoesFirst():\n", + "\n", + " # Randomly choose the player who goes first.\n", + "\n", + " if random.randint(0, 1) == 0:\n", + " return 'computer'\n", + "\n", + " else:\n", + " return 'player'\n", + "\n", + "def playAgain():\n", + "\n", + " # This function returns True if the player wants to play again, otherwise it returns False.\n", + " \n", + " print('Do you want to play again? (yes or no)')\n", + " return input().lower().startswith('y')\n", + " \n", + "def makeMove(board, letter, move):\n", + " board[move] = letter\n", + "\n", + "def isWinner(bo, le):\n", + "\n", + "# Given a board and a player’s letter, this function returns True if that player has won.\n", + "\n", + "# We use bo instead of board and le instead of letter so we don’t have to type as much.\n", + "\n", + " return ((bo[7] == le and bo[8] == le and bo[9] == le) or # across the top\n", + "\n", + " (bo[4] == le and bo[5] == le and bo[6] == le) or # across the middle\n", + "\n", + " (bo[1] == le and bo[2] == le and bo[3] == le) or # across the bottom\n", + "\n", + " (bo[7] == le and bo[4] == le and bo[1] == le) or # down the left side\n", + "\n", + " (bo[8] == le and bo[5] == le and bo[2] == le) or # down the middle\n", + "\n", + " (bo[9] == le and bo[6] == le and bo[3] == le) or # down the right side\n", + "\n", + " (bo[7] == le and bo[5] == le and bo[3] == le) or # diagonal\n", + "\n", + " (bo[9] == le and bo[5] == le and bo[1] == le)) # diagonal\n", + "\n", + "def getBoardCopy(board):\n", + " # Make a duplicate of the board list and return it the duplicate.\n", + "\n", + " dupeBoard = []\n", + "\n", + " for i in board:\n", + " dupeBoard.append(i)\n", + "\n", + " return dupeBoard\n", + "\n", + "def isSpaceFree(board, move):\n", + "# Return true if the passed move is free on the passed board.\n", + " return board[move] == ' '\n", + "\n", + "def getPlayerMove(board):\n", + "\n", + "# Let the player type in their move.\n", + "\n", + " move = ' '\n", + "\n", + " while move not in '1 2 3 4 5 6 7 8 9'.split() or not isSpaceFree(board, int(move)):\n", + " print('What is your next move? (1-9)')\n", + " move = input()\n", + " return int(move)\n", + "\n", + "def chooseRandomMoveFromList(board, movesList):\n", + "\n", + "# Returns a valid move from the passed list on the passed board.\n", + "# Returns None if there is no valid move.\n", + " possibleMoves = []\n", + " for i in movesList:\n", + " if isSpaceFree(board, i):\n", + " possibleMoves.append(i)\n", + "\n", + " if len(possibleMoves) != 0:\n", + " return random.choice(possibleMoves)\n", + "\n", + " else:\n", + " return None\n", + "\n", + "def getComputerMove(board, computerLetter):\n", + "\n", + "# Given a board and the computer's letter, determine where to move and return that move.\n", + "\n", + " if computerLetter == 'X':\n", + " playerLetter = 'O'\n", + "\n", + " else:\n", + " playerLetter = 'X'\n", + "\n", + "# Here is our algorithm for our Tic Tac Toe AI:\n", + "# First, check if we can win in the next move\n", + "\n", + " for i in range(1, 10):\n", + " copy = getBoardCopy(board)\n", + " if isSpaceFree(copy, i):\n", + " makeMove(copy, computerLetter, i)\n", + " if isWinner(copy, computerLetter):\n", + " return i\n", + "\n", + "# Check if the player could win on their next move, and block them.\n", + "\n", + " for i in range(1, 10):\n", + " copy = getBoardCopy(board)\n", + " if isSpaceFree(copy, i):\n", + " makeMove(copy, playerLetter, i)\n", + " if isWinner(copy, playerLetter):\n", + " return i\n", + "\n", + "# Try to take one of the corners, if they are free.\n", + "\n", + " move = chooseRandomMoveFromList(board, [1, 3, 7, 9])\n", + " if move != None:\n", + " return move\n", + "# Try to take the center, if it is free.\n", + "\n", + " if isSpaceFree(board, 5):\n", + " return 5\n", + "# Move on one of the sides.\n", + " return chooseRandomMoveFromList(board, [2, 4, 6, 8])\n", + "\n", + "def isBoardFull(board):\n", + "# Return True if every space on the board has been taken. Otherwise return False.\n", + " for i in range(1, 10):\n", + " if isSpaceFree(board, i):\n", + " return False\n", + " return True\n", + "print('Welcome to Tic Tac Toe!')\n", + "\n", + "while True:\n", + "# Reset the board\n", + " theBoard = [' '] * 10\n", + " playerLetter, computerLetter = inputPlayerLetter()\n", + " turn = whoGoesFirst()\n", + " print('The ' + turn + ' will go first.')\n", + " gameIsPlaying = True\n", + " \n", + " while gameIsPlaying:\n", + " if turn == 'player':\n", + " # Player’s turn.\n", + " drawBoard(theBoard)\n", + " move = getPlayerMove(theBoard)\n", + " makeMove(theBoard, playerLetter, move)\n", + " \n", + " if isWinner(theBoard, playerLetter):\n", + " drawBoard(theBoard)\n", + " print('Hooray! You have won the game!')\n", + " gameIsPlaying = False\n", + "\n", + " else:\n", + " if isBoardFull(theBoard):\n", + " drawBoard(theBoard)\n", + " print('The game is a tie!')\n", + " break\n", + " else:\n", + " turn = 'computer'\n", + " else:\n", + " # Computer’s turn.\n", + " move = getComputerMove(theBoard, computerLetter)\n", + " makeMove(theBoard, computerLetter, move)\n", + " if isWinner(theBoard, computerLetter):\n", + " drawBoard(theBoard)\n", + " print('The computer has beaten you! You lose.')\n", + " gameIsPlaying = False\n", + " else:\n", + " if isBoardFull(theBoard):\n", + " drawBoard(theBoard)\n", + " print('The game is a tie!')\n", + " break\n", + " else:\n", + " turn = 'player'\n", + " if not playAgain():\n", + " break" + ] + } + ], + "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 +} From acc9cd55983476975e02b888c32879fcb3d3e4ba Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 27 Mar 2020 10:52:44 -0500 Subject: [PATCH 06/12] HW-4: Md Arifur Rahman --- Labs/Lab-4/Lab-4-Submission.ipynb | 1067 +++++++++++++++++++++++++++++ 1 file changed, 1067 insertions(+) create mode 100644 Labs/Lab-4/Lab-4-Submission.ipynb diff --git a/Labs/Lab-4/Lab-4-Submission.ipynb b/Labs/Lab-4/Lab-4-Submission.ipynb new file mode 100644 index 0000000..b9c41d9 --- /dev/null +++ b/Labs/Lab-4/Lab-4-Submission.ipynb @@ -0,0 +1,1067 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "h5Q5XArdIQ7l" + }, + "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": 2, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "HxvJuGAAIQ7p" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The Value of x is 0.5574752118833375\n" + ] + } + ], + "source": [ + "import random\n", + "x=random.random()\n", + "print (\"The Value of x is\", x)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ZBPVSjQtIQ79" + }, + "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": 3, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "QP4JyGB3IQ7_" + }, + "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": 4, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[128, 595, 508, 784, 974, 94, 917, 526, 783, 142, 894, 264, 94, 43, 374, 305, 594, 491, 771, 284]\n" + ] + } + ], + "source": [ + "# Testing \n", + "N = 20\n", + "x_min = 10\n", + "x_max = 1000\n", + "x=generate_uniform(N, x_min, x_max)\n", + "print(x) " + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "9CtuMQ7eIQ8H" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Data Type: \n", + "Data Length: 1000\n", + "Type of Data Contents: \n", + "Data Minimum: -10\n", + "Data Maximum: 10\n" + ] + } + ], + "source": [ + "# Test you solution here\n", + "data=generate_uniform(1000,-10,10)\n", + "print (\"Data Type:\", type(data))\n", + "print (\"Data Length:\", len(data))\n", + "if len(data)>0: \n", + " print (\"Type of Data Contents:\", type(data[0]))\n", + " print (\"Data Minimum:\", min(data))\n", + " print (\"Data Maximum:\", max(data))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "Txq5nj9YIQ8M" + }, + "source": [ + "*Exercise 2a:* \n", + "Write a function that computes the mean of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "VL8WtAJcIQ8P" + }, + "outputs": [], + "source": [ + "# Skeleton\n", + "def mean(Data): \n", + " m= sum(Data, 0.0) / len(Data)\n", + " \n", + " return m" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Mvx7bXw2IQ8W" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of Data: 478.25\n", + "Mean of Data: 5.5\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "data1 = list(range(1,11))\n", + "print (\"Mean of Data:\", mean(x))\n", + "print (\"Mean of Data:\", mean(data1))\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "9ssysQGdIQ8a" + }, + "source": [ + "*Exercise 2b:* \n", + "Write a function that computes the variance of values in a list." + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "16ySAPEaIQ8c" + }, + "outputs": [], + "source": [ + "# Skeleton\n", + "def variance(Data):\n", + " total = 0.0\n", + " for i in Data:\n", + " sum_total =(i - mean(Data))**2\n", + " total +=sum_total\n", + " var = total/(len(Data)-1)\n", + " \n", + " return var\n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "W2528u2XIQ8j" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Variance of Data: 92554.19736842105\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "print (\"Variance of Data:\", variance(x))" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Variance of Data: 32.024849178421285\n" + ] + } + ], + "source": [ + "results = [-14.82381293, -0.29423447, -13.56067979, -1.6288903, -0.31632439,\n", + " 0.53459687, -1.34069996, -1.61042692, -4.03220519, -0.24332097]\n", + "print (\"Variance of Data:\", variance(results))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "iRCc06j7IQ8o" + }, + "source": [ + "## Histogramming" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "keq79QLTIQ8p" + }, + "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": 15, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "bhJdNLobIQ8r" + }, + "outputs": [], + "source": [ + "# Solution\n", + "x = generate_uniform(20, 0, 1000)\n", + "def histogram(x,n_bins=10,x_min=None,x_max=None):\n", + " ### BEGIN SOLUTION\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", + " bin_edges = list()\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " for item in x:\n", + " for i in range(n_bins):\n", + " if x_min+i*bin_size <= item <= x_min+(i+1)*bin_size:\n", + " hist[i] +=1 \n", + " bin_edges = [round(x,2) for x in bin_edges]\n", + " return hist,bin_edges\n" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "([3, 2, 4, 1, 3, 1, 2, 2, 0, 2], [40.0, 134.6, 229.2, 323.8, 418.4, 513.0, 607.6, 702.2, 796.8, 891.4, 986.0])\n" + ] + } + ], + "source": [ + "# Test your solution here\n", + "print(histogram(x,n_bins=10))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "xYbLbQVbIQ82" + }, + "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, 9] : ######\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": 17, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "o2rLSzI_IQ84" + }, + "outputs": [], + "source": [ + "# Solution\n", + "def draw_histogram(x,n_bins,x_min=None,x_max=None,character=\"#\",max_character_per_line=20):\n", + " ### BEGIN SOLUTION\n", + " x_min = min(x)\n", + " x_max = max(x)\n", + " bin_size = (x_max-x_min)/n_bins\n", + " hist= [0]*n_bins\n", + " bin_edges = list()\n", + " for edge in range(n_bins+1):\n", + " bin_edges.append(x_min+edge*bin_size)\n", + " for item in x:\n", + " for i in range(n_bins):\n", + " if x_min+i*bin_size <= item <= x_min+(i+1)*bin_size:\n", + " hist[i] +=1 \n", + " bin_edges = [round(x,2) for x in bin_edges] \n", + " for i, j in enumerate(hist):\n", + " print(f\"[ {bin_edges[i]} , {bin_edges[i+1]} ] : {int(hist[i])*character} \")\n", + " \n", + " return hist,bin_edges" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "tW1_Rnj2IQ88" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 40.0 , 134.6 ] : ### \n", + "[ 134.6 , 229.2 ] : ## \n", + "[ 229.2 , 323.8 ] : #### \n", + "[ 323.8 , 418.4 ] : # \n", + "[ 418.4 , 513.0 ] : ### \n", + "[ 513.0 , 607.6 ] : # \n", + "[ 607.6 , 702.2 ] : ## \n", + "[ 702.2 , 796.8 ] : ## \n", + "[ 796.8 , 891.4 ] : \n", + "[ 891.4 , 986.0 ] : ## \n" + ] + }, + { + "data": { + "text/plain": [ + "([3, 2, 4, 1, 3, 1, 2, 2, 0, 2],\n", + " [40.0, 134.6, 229.2, 323.8, 418.4, 513.0, 607.6, 702.2, 796.8, 891.4, 986.0])" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# Test your solution here\n", + "draw_histogram(x,10)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "9xOOI51iIQ9A" + }, + "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": 19, + "metadata": {}, + "outputs": [], + "source": [ + "def where(mylist,myfunc):\n", + " out = []\n", + " for i,val in enumerate(mylist):\n", + " if myfunc(val):\n", + " out.append(i)\n", + " \n", + " return out\n", + "#f = lambda x: x>0.5" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 5, 6, 9]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "lst = [0.7,-0.1,5,0.2,9,1.6,7,-0.7,0.5,0.6]\n", + "where(lst,lambda x: x>0.5)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[0, 2, 4, 5, 6, 9, 11]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "data = generate_uniform(20, 0, 1000)\n", + "l = [0.7,-0.1,5,0.2,9,1.6,7,-0.7,0.5,0.6,-7,2]\n", + "where(l,lambda x: x>0.5)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "km1Nbsq5IQ9L" + }, + "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": 22, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "thDnjHdrIQ9N" + }, + "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: 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(l,F1)))\n", + "print (\"Number of Entries passing F2:\", len(where(l,F2)))" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "sL6knjoZIQ9Q" + }, + "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", + "def greater_than(x,y):\n", + " return x>y\n", + "\n", + "def less_than(x,y):\n", + " return xy\n", + "\n", + "less_than =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": 29, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "hLS9VHV-IQ9f" + }, + "outputs": [], + "source": [ + "def generate_function(func,x_min,x_max,N=1000):\n", + " import random\n", + " out = list()\n", + " while True:\n", + " test_x=random.choice(range(x_min,x_max))\n", + " p=random.choice(range(x_min,x_max))\n", + " if p<=func(test_x):\n", + " out.append(test_x)\n", + " if len(out) ==N:\n", + " break\n", + " \n", + " return out" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "SXRrs-n7IQ9i" + }, + "outputs": [], + "source": [ + "# A test function\n", + "def test_func(x,a=1,b=1):\n", + " return abs(a*x+b)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7, 7, 5, 4, 4, 3, 2, 0, 7, 8, 9, 7, 8, 9, 9, 4, 2, 1, 6, 7, 8, 8, 8, 9, 6, 9, 5, 7, 8, 6, 7, 6, 9, 8, 4, 7, 8, 2, 9, 3, 8, 3, 9, 8, 7, 9, 9, 9, 6, 3, 1, 6, 6, 2, 5, 9, 2, 7, 2, 5, 6, 5, 7, 2, 6, 5, 9, 2, 2, 3, 7, 0, 8, 6, 6, 5, 6, 6, 2, 2, 8, 3, 6, 3, 1, 8, 1, 1, 1, 8, 2, 0, 1, 8, 1, 8, 8, 8, 6, 1, 8, 8, 5, 3, 6, 9, 9, 2, 7, 1, 8, 9, 8, 1, 9, 8, 5, 1, 5, 3, 6, 2, 9, 3, 0, 5, 0, 7, 4, 9, 0, 8, 4, 7, 7, 5, 7, 5, 3, 7, 9, 4, 9, 5, 3, 8, 3, 9, 6, 2, 6, 6, 6, 4, 8, 5, 8, 7, 0, 9, 8, 2, 8, 7, 8, 7, 9, 5, 8, 3, 8, 8, 0, 7, 4, 1, 8, 1, 2, 0, 2, 9, 3, 5, 6, 8, 1, 8, 4, 4, 6, 7, 8, 8, 9, 8, 4, 5, 9, 4, 6, 4, 3, 3, 3, 1, 3, 7, 8, 2, 4, 7, 2, 9, 4, 3, 6, 4, 3, 5, 7, 3, 3, 7, 1, 3, 5, 9, 5, 6, 0, 8, 5, 6, 8, 7, 3, 9, 5, 3, 9, 9, 6, 8, 6, 2, 8, 9, 2, 6, 5, 3, 3, 9, 8, 7, 6, 4, 9, 4, 9, 8, 3, 5, 0, 9, 7, 3, 1, 7, 7, 6, 4, 6, 7, 9, 7, 4, 4, 7, 6, 3, 7, 9, 5, 8, 2, 4, 7, 5, 0, 3, 6, 3, 7, 2, 8, 0, 8, 5, 2, 2, 5, 7, 8, 6, 6, 7, 8, 5, 7, 7, 9, 6, 8, 2, 8, 2, 2, 9, 3, 7, 1, 4, 8, 5, 5, 9, 8, 5, 6, 5, 3, 4, 2, 7, 9, 7, 9, 6, 8, 7, 7, 6, 5, 9, 5, 8, 5, 5, 5, 3, 9, 5, 5, 4, 9, 7, 7, 3, 8, 5, 6, 6, 6, 7, 8, 8, 1, 4, 3, 4, 7, 9, 5, 3, 4, 6, 9, 5, 5, 9, 8, 4, 6, 7, 8, 4, 6, 5, 5, 3, 4, 5, 6, 8, 5, 9, 6, 7, 7, 8, 6, 6, 9, 3, 9, 7, 9, 9, 4, 7, 5, 9, 3, 6, 5, 7, 2, 6, 9, 3, 5, 0, 9, 6, 0, 8, 8, 4, 8, 5, 8, 3, 9, 4, 7, 8, 6, 8, 7, 7, 5, 9, 9, 1, 3, 4, 8, 7, 9, 3, 4, 8, 6, 8, 9, 6, 5, 3, 9, 6, 4, 8, 4, 3, 4, 3, 3, 8, 8, 2, 7, 9, 8, 8, 8, 9, 6, 9, 9, 6, 7, 0, 3, 4, 0, 3, 8, 4, 8, 4, 9, 9, 8, 0, 9, 8, 9, 8, 5, 3, 8, 6, 4, 5, 9, 3, 9, 9, 4, 4, 6, 2, 8, 7, 6, 1, 9, 7, 3, 6, 9, 6, 8, 3, 9, 9, 6, 7, 8, 0, 0, 2, 8, 8, 2, 9, 9, 8, 6, 8, 8, 6, 6, 9, 3, 9, 7, 7, 6, 9, 8, 6, 6, 8, 8, 4, 7, 9, 8, 2, 8, 9, 7, 8, 2, 5, 2, 4, 6, 7, 4, 6, 5, 3, 4, 7, 4, 4, 3, 0, 6, 7, 6, 3, 1, 4, 1, 9, 6, 5, 0, 5, 7, 6, 4, 9, 8, 1, 9, 6, 5, 4, 3, 1, 3, 5, 3, 9, 8, 9, 2, 2, 5, 9, 5, 4, 9, 4, 5, 8, 8, 9, 2, 8, 6, 6, 3, 8, 4, 9, 7, 7, 9, 6, 5, 9, 1, 4, 6, 9, 9, 9, 9, 2, 5, 0, 9, 3, 8, 9, 8, 3, 0, 7, 6, 8, 4, 8, 0, 2, 8, 5, 8, 8, 0, 5, 7, 9, 5, 1, 9, 2, 2, 1, 8, 2, 4, 6, 2, 0, 6, 3, 8, 4, 5, 3, 0, 5, 6, 8, 4, 7, 8, 6, 6, 5, 2, 5, 1, 5, 7, 9, 6, 9, 6, 8, 7, 3, 4, 4, 9, 1, 8, 5, 5, 7, 8, 6, 7, 0, 7, 9, 6, 2, 6, 7, 3, 8, 8, 5, 9, 4, 5, 2, 2, 6, 3, 5, 6, 7, 5, 2, 9, 6, 8, 7, 3, 8, 4, 8, 8, 8, 8, 7, 6, 9, 6, 8, 7, 8, 9, 8, 6, 9, 4, 8, 8, 7, 5, 9, 8, 7, 7, 5, 8, 9, 9, 7, 9, 5, 8, 7, 4, 6, 6, 5, 4, 4, 7, 7, 6, 9, 7, 0, 8, 9, 9, 3, 0, 8, 9, 6, 3, 9, 5, 9, 5, 7, 6, 4, 4, 9, 7, 8, 8, 4, 9, 1, 5, 3, 2, 7, 8, 8, 5, 9, 8, 6, 6, 8, 9, 8, 0, 4, 3, 7, 8, 8, 5, 7, 7, 7, 7, 7, 9, 4, 4, 2, 3, 8, 8, 8, 4, 3, 8, 9, 7, 9, 5, 4, 9, 5, 7, 1, 5, 9, 7, 1, 9, 1, 9, 8, 6, 7, 8, 4, 8, 2, 8, 9, 9, 9, 9, 7, 7, 7, 6, 9, 8, 8, 6, 8, 8, 6, 4, 7, 6, 9, 8, 6, 7, 6, 5, 1, 6, 3, 0, 8, 7, 2, 7, 9, 5, 9, 4, 6, 8, 8, 1, 2, 5, 9, 2, 5, 9, 6, 5, 3, 7, 3, 8, 8, 9, 3, 6, 6, 9, 2, 2, 4, 8, 4, 7, 2, 6, 7, 4, 9, 5, 8, 8, 7, 6, 8, 1, 8, 5, 9, 7, 7, 2, 2, 3, 0, 4, 8, 8, 1, 2, 3, 6, 2, 9, 1, 8, 7, 5, 6, 8, 9, 8, 4, 2, 4, 1, 5, 1, 2, 9, 5, 6, 8, 4, 1, 8, 7, 2, 9]\n" + ] + } + ], + "source": [ + "x=generate_function(test_func,0,10)\n", + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0.0 , 0.9 ] : ################################## \n", + "[ 0.9 , 1.8 ] : ########################################### \n", + "[ 1.8 , 2.7 ] : #################################################################### \n", + "[ 2.7 , 3.6 ] : #################################################################################### \n", + "[ 3.6 , 4.5 ] : ######################################################################################### \n", + "[ 4.5 , 5.4 ] : ######################################################################################################## \n", + "[ 5.4 , 6.3 ] : ############################################################################################################################ \n", + "[ 6.3 , 7.2 ] : ############################################################################################################################# \n", + "[ 7.2 , 8.1 ] : ################################################################################################################################################################################ \n", + "[ 8.1 , 9.0 ] : ######################################################################################################################################################### \n" + ] + }, + { + "data": { + "text/plain": [ + "([34, 43, 68, 84, 89, 104, 124, 125, 176, 153],\n", + " [0.0, 0.9, 1.8, 2.7, 3.6, 4.5, 5.4, 6.3, 7.2, 8.1, 9.0])" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "draw_histogram(x,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mean : 5.711\n", + "variance : 6.732211211211208\n" + ] + } + ], + "source": [ + "m =mean(x)\n", + "v =variance(x)\n", + "print(\"mean :\",m)\n", + "print(\"variance :\",v)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "TSJNFJ6lIQ9n" + }, + "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": null, + "metadata": {}, + "outputs": [], + "source": [ + "def normal(x,mu,sigma):\n", + " return ( 2.*np.pi*sigma**2. )**-.5 * np.exp( -.5 * (x-mu)**2. / sigma**2. )" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ibYoQs0eIQ9o" + }, + "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(5.711,6.732211211211208)\n", + "g2=gaussian(10,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 0, 1, 1, 8, 7, 2, 4, 0, 4, 1, 7, 9, 5, 3, 7, 0, 1, 0, 1, 1, 2, 3, 6, 9, 8, 0, 9, 9, 4, 2, 0, 5, 0, 4, 4, 9, 0, 1, 0, 6, 4, 0, 0, 7, 5, 2, 1, 1, 7, 5, 1, 5, 7, 7, 7, 9, 8, 9, 9, 4, 1, 0, 2, 5, 2, 4, 5, 8, 5, 3, 2, 7, 6, 6, 1, 0, 7, 1, 5, 5, 3, 5, 3, 1, 9, 3, 5, 1, 5, 6, 7, 8, 3, 7, 3, 0, 6, 5, 7, 7, 9, 1, 2, 9, 7, 3, 0, 2, 5, 7, 9, 6, 6, 6, 0, 1, 6, 1, 8, 5, 0, 7, 6, 9, 1, 6, 4, 1, 8, 2, 2, 5, 2, 1, 9, 3, 0, 1, 2, 7, 6, 9, 9, 0, 2, 8, 2, 1, 3, 3, 3, 2, 7, 8, 9, 0, 7, 9, 0, 6, 2, 0, 9, 5, 4, 2, 1, 0, 0, 9, 1, 4, 1, 8, 7, 4, 1, 7, 3, 1, 2, 0, 3, 8, 7, 7, 7, 2, 7, 2, 7, 0, 2, 0, 5, 9, 1, 6, 2, 2, 2, 6, 0, 6, 4, 1, 0, 7, 8, 8, 9, 8, 0, 2, 5, 1, 9, 7, 5, 4, 4, 2, 5, 1, 0, 3, 0, 4, 5, 5, 5, 1, 6, 4, 7, 9, 4, 3, 8, 4, 3, 0, 8, 4, 8, 8, 2, 3, 7, 8, 1, 4, 8, 0, 9, 6, 0, 5, 4, 7, 9, 0, 6, 7, 8, 7, 4, 9, 2, 8, 0, 4, 3, 8, 0, 7, 3, 4, 1, 5, 4, 2, 1, 9, 3, 3, 0, 9, 0, 2, 9, 2, 3, 8, 9, 8, 5, 0, 0, 2, 8, 2, 8, 4, 5, 3, 0, 4, 0, 4, 8, 7, 9, 7, 8, 7, 4, 7, 2, 3, 8, 8, 4, 3, 7, 1, 2, 4, 1, 0, 0, 1, 8, 2, 5, 4, 1, 4, 9, 6, 7, 2, 6, 6, 7, 8, 1, 6, 8, 4, 4, 7, 1, 3, 3, 0, 2, 5, 4, 7, 3, 4, 0, 5, 5, 7, 2, 3, 6, 4, 8, 3, 9, 1, 6, 4, 8, 9, 5, 8, 8, 3, 5, 0, 6, 1, 1, 3, 3, 1, 3, 1, 1, 0, 7, 3, 6, 6, 3, 1, 4, 1, 3, 2, 1, 8, 5, 6, 5, 4, 6, 0, 9, 0, 2, 9, 9, 9, 9, 8, 8, 5, 4, 0, 0, 3, 7, 9, 5, 7, 9, 2, 6, 8, 7, 2, 6, 1, 7, 1, 9, 8, 7, 0, 2, 2, 4, 2, 1, 6, 6, 5, 4, 6, 8, 6, 4, 7, 6, 1, 0, 0, 0, 2, 2, 5, 6, 0, 2, 1, 2, 6, 4, 8, 1, 1, 1, 0, 2, 4, 7, 5, 7, 1, 9, 3, 3, 9, 1, 0, 8, 8, 9, 2, 6, 0, 5, 2, 0, 7, 0, 8, 7, 6, 1, 6, 7, 3, 0, 2, 1, 3, 6, 7, 3, 0, 9, 7, 1, 0, 4, 9, 2, 1, 1, 0, 7, 4, 9, 9, 0, 8, 7, 0, 2, 4, 1, 0, 3, 3, 6, 2, 2, 9, 7, 4, 2, 3, 0, 5, 6, 5, 9, 4, 6, 3, 6, 8, 7, 5, 9, 6, 6, 9, 9, 7, 4, 8, 3, 9, 6, 4, 1, 5, 3, 0, 1, 6, 4, 9, 8, 6, 5, 9, 3, 0, 7, 8, 3, 5, 5, 5, 6, 4, 6, 7, 7, 8, 3, 6, 1, 1, 8, 5, 7, 9, 2, 4, 0, 7, 6, 6, 8, 3, 1, 9, 9, 8, 3, 7, 8, 9, 8, 9, 0, 2, 6, 3, 2, 8, 7, 5, 2, 3, 0, 3, 4, 0, 2, 5, 5, 0, 8, 2, 8, 4, 0, 3, 8, 8, 4, 0, 8, 4, 3, 3, 8, 3, 4, 8, 7, 7, 9, 8, 3, 1, 1, 0, 1, 5, 0, 9, 9, 1, 9, 8, 7, 3, 9, 8, 4, 8, 4, 2, 2, 1, 7, 7, 5, 5, 4, 2, 2, 0, 2, 6, 4, 6, 8, 5, 4, 7, 0, 6, 3, 4, 2, 7, 1, 5, 8, 2, 7, 3, 3, 9, 5, 6, 9, 1, 8, 0, 9, 4, 7, 2, 2, 3, 7, 3, 2, 3, 5, 1, 6, 8, 5, 8, 6, 4, 4, 8, 4, 7, 0, 7, 6, 5, 2, 2, 6, 4, 2, 5, 8, 7, 8, 8, 5, 5, 7, 0, 1, 3, 1, 1, 2, 7, 5, 4, 2, 7, 3, 8, 0, 2, 1, 0, 2, 9, 6, 3, 1, 1, 6, 7, 1, 6, 0, 3, 5, 8, 5, 1, 9, 7, 2, 0, 2, 2, 5, 9, 4, 3, 5, 9, 8, 6, 7, 4, 6, 6, 3, 0, 5, 8, 1, 0, 3, 2, 3, 9, 6, 2, 3, 7, 1, 4, 9, 6, 8, 7, 8, 5, 5, 3, 1, 9, 1, 6, 4, 0, 9, 7, 2, 7, 5, 9, 4, 4, 0, 9, 3, 7, 8, 6, 6, 7, 5, 0, 2, 2, 3, 4, 9, 5, 5, 4, 7, 3, 5, 1, 2, 2, 9, 3, 0, 0, 2, 1, 1, 4, 6, 5, 1, 9, 4, 1, 6, 5, 9, 1, 7, 5, 5, 3, 6, 7, 3, 0, 6, 3, 9, 9, 9, 0, 0, 9, 0, 5, 1, 2, 6, 5, 8, 0, 8, 3, 4, 9, 0, 4, 6, 6, 3, 0, 1, 4, 3, 1, 7, 5, 1, 5, 8, 0, 3, 5, 7, 4, 4, 3, 8, 9, 3, 1, 5, 6, 0, 0, 7, 8, 3, 0, 6, 8, 3, 7, 0, 9, 4, 6, 8, 7, 2, 3, 5, 2, 4, 4, 6, 8, 4, 9, 4, 2, 4, 3, 5, 2, 5, 1, 6, 9, 5, 6, 7, 0, 7, 4, 5, 7, 9, 1, 3, 9, 5, 6, 2]\n" + ] + } + ], + "source": [ + "x=generate_function(g1,0,10)\n", + "print(x)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[ 0.0 , 0.9 ] : ################################################################################################################# \n", + "[ 0.9 , 1.8 ] : ######################################################################################################### \n", + "[ 1.8 , 2.7 ] : #################################################################################################### \n", + "[ 2.7 , 3.6 ] : ################################################################################################### \n", + "[ 3.6 , 4.5 ] : ################################################################################################# \n", + "[ 4.5 , 5.4 ] : ################################################################################################ \n", + "[ 5.4 , 6.3 ] : ############################################################################################ \n", + "[ 6.3 , 7.2 ] : ########################################################################################################### \n", + "[ 7.2 , 8.1 ] : ############################################################################################### \n", + "[ 8.1 , 9.0 ] : ################################################################################################ \n" + ] + }, + { + "data": { + "text/plain": [ + "([113, 105, 100, 99, 97, 96, 92, 107, 95, 96],\n", + " [0.0, 0.9, 1.8, 2.7, 3.6, 4.5, 5.4, 6.3, 7.2, 8.1, 9.0])" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "draw_histogram(x,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "mean : 4.395\n", + "variance : 8.451426426426545\n" + ] + } + ], + "source": [ + "m =mean(x)\n", + "v =variance(x)\n", + "print(\"mean :\",m)\n", + "print(\"variance :\",v)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "Q4DVjd3IIQ9q" + }, + "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": "M-eIBsdQIQ9r" + }, + "outputs": [], + "source": [ + "def integrate(func, x_min, x_max, n_points=1000):\n", + " x=generate_function(g1,0,10)\n", + " \n", + " where(lst,lambda x: x>1)\n", + " \n", + " F1=inrange(0,10)\n", + " \n", + " return integral" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "Ce6bnXzrIQ9v" + }, + "outputs": [], + "source": [ + "import math\n", + "def integrate(func, x_min, x_max, n_points=1000):\n", + " x=generate_function(g1,0,10)\n", + " h = (x_max-x_min)/float(n_points)\n", + " s = 0.5*(func(x_min) + func(x_max))\n", + " for i in range(1,n_points,1):\n", + " s = s + func(x_min + i*h)\n", + " return h*s\n", + "\n", + " #where(lst,lambda x: x>1)\n", + " #F1=inrange(x_min,x_max)\n", + "def integral(x):\n", + " constant = 1.0 / math.sqrt(2*math.pi)\n", + " return(constant * math.exp((-x**2) / 2.0) )" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.6826893308232487\n" + ] + } + ], + "source": [ + "result = integrate(integral, -1, 1)\n", + "print (result)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.9973001241637547\n" + ] + } + ], + "source": [ + "result = integrate(integral, -3, 3)\n", + "print (result)" + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.954499448151897\n" + ] + } + ], + "source": [ + "result = integrate(integral, -2, 2,1000)\n", + "print (result)" + ] + } + ], + "metadata": { + "colab": { + "name": "Copy of Lab-4.ipynb", + "provenance": [ + { + "file_id": "https://github.com/afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-4/Lab-4.ipynb", + "timestamp": 1582311752013 + } + ] + }, + "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 +} From fa5e6b5264d159acafdd9ba43d5e3f1d8d05e86d Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Mon, 30 Mar 2020 21:56:41 -0500 Subject: [PATCH 07/12] I made this compatible with python 3.5 --- Labs/Lab-3/Lab-3-Submission.ipynb | 107 +++++++++++++++++++----------- 1 file changed, 68 insertions(+), 39 deletions(-) diff --git a/Labs/Lab-3/Lab-3-Submission.ipynb b/Labs/Lab-3/Lab-3-Submission.ipynb index b3769ac..96d80b8 100644 --- a/Labs/Lab-3/Lab-3-Submission.ipynb +++ b/Labs/Lab-3/Lab-3-Submission.ipynb @@ -26,7 +26,7 @@ }, { "cell_type": "code", - "execution_count": 391, + "execution_count": 1, "metadata": { "colab": {}, "colab_type": "code", @@ -51,7 +51,7 @@ " [0, 0, 0, 0, 0]]" ] }, - "execution_count": 391, + "execution_count": 1, "metadata": {}, "output_type": "execute_result" } @@ -74,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": 392, + "execution_count": 2, "metadata": {}, "outputs": [ { @@ -87,7 +87,7 @@ " [0, 0, 0, 0, 0]]" ] }, - "execution_count": 392, + "execution_count": 2, "metadata": {}, "output_type": "execute_result" } @@ -113,7 +113,7 @@ }, { "cell_type": "code", - "execution_count": 393, + "execution_count": 3, "metadata": { "colab": {}, "colab_type": "code", @@ -148,7 +148,7 @@ }, { "cell_type": "code", - "execution_count": 394, + "execution_count": 4, "metadata": { "colab": {}, "colab_type": "code", @@ -227,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 395, + "execution_count": 5, "metadata": { "colab": {}, "colab_type": "code", @@ -270,7 +270,7 @@ }, { "cell_type": "code", - "execution_count": 396, + "execution_count": 6, "metadata": { "colab": {}, "colab_type": "code", @@ -316,7 +316,7 @@ }, { "cell_type": "code", - "execution_count": 397, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -340,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": 398, + "execution_count": 8, "metadata": {}, "outputs": [ { @@ -373,7 +373,7 @@ }, { "cell_type": "code", - "execution_count": 399, + "execution_count": 8, "metadata": { "colab": {}, "colab_type": "code", @@ -404,7 +404,7 @@ }, { "cell_type": "code", - "execution_count": 415, + "execution_count": 9, "metadata": {}, "outputs": [ { @@ -425,7 +425,7 @@ " [2, 1, 1, 0, 1]]" ] }, - "execution_count": 415, + "execution_count": 9, "metadata": {}, "output_type": "execute_result" } @@ -439,7 +439,8 @@ " [2, 1, 1,0,1]]\n", "\n", "place_piece(board_5X5,player_1,(0,2))\n", - "gameboard" + "#gboard=tic_tac_toe_board(board_5X5)\n", + "board_5X5" ] }, { @@ -454,7 +455,7 @@ }, { "cell_type": "code", - "execution_count": 401, + "execution_count": 10, "metadata": { "colab": {}, "colab_type": "code", @@ -487,7 +488,7 @@ }, { "cell_type": "code", - "execution_count": 403, + "execution_count": 11, "metadata": {}, "outputs": [ { @@ -525,7 +526,7 @@ }, { "cell_type": "code", - "execution_count": 404, + "execution_count": 12, "metadata": { "colab": {}, "colab_type": "code", @@ -537,7 +538,7 @@ "def print_message(message,verbose=True):\n", " if verbose:\n", " print(message)\n", - " \n", + "\n", "\n", "def specified_location(l_string):\n", " if not isinstance(l_string,str):\n", @@ -573,7 +574,19 @@ }, { "cell_type": "code", - "execution_count": 406, + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "row_names=list(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n", + "row_map=dict(zip(row_names,range(size)))\n", + "column_names=list(map(str,range(1,size+1)))\n", + "column_map=dict(zip(column_names,range(size)))" + ] + }, + { + "cell_type": "code", + "execution_count": 15, "metadata": { "colab": {}, "colab_type": "code", @@ -610,7 +623,7 @@ }, { "cell_type": "code", - "execution_count": 408, + "execution_count": 16, "metadata": {}, "outputs": [ { @@ -618,7 +631,7 @@ "output_type": "stream", "text": [ " 1 2 3 4 5 \n", - "A X O O X \n", + "A X O X \n", "B X X O \n", "C O X X O X \n", "D O X X X O \n", @@ -626,7 +639,7 @@ "player does not have piece at (0, 2) location. True\n", "Successfully Placed Player 2! True\n", " 1 2 3 4 5 \n", - "A X O O O X \n", + "A X O O X \n", "B X X O \n", "C O X X O X \n", "D O X X X O \n", @@ -652,7 +665,7 @@ }, { "cell_type": "code", - "execution_count": 409, + "execution_count": 17, "metadata": { "colab": {}, "colab_type": "code", @@ -672,7 +685,7 @@ }, { "cell_type": "code", - "execution_count": 410, + "execution_count": 18, "metadata": { "colab": {}, "colab_type": "code", @@ -684,7 +697,7 @@ "output_type": "stream", "text": [ " 1 2 3 4 5 \n", - "A X O O O X \n", + "A X O O X \n", "B X X O \n", "C O X X O X \n", "D O X X X O \n", @@ -693,7 +706,7 @@ "player does not have piece at (1, 0) location. True\n", "Successfully Placed Player 2! True\n", " 1 2 3 4 5 \n", - "A X O O O X \n", + "A X O O X \n", "B O X X O \n", "C O X X O X \n", "D O X X X O \n", @@ -720,7 +733,7 @@ }, { "cell_type": "code", - "execution_count": 411, + "execution_count": 19, "metadata": { "colab": {}, "colab_type": "code", @@ -766,7 +779,7 @@ }, { "cell_type": "code", - "execution_count": 412, + "execution_count": 43, "metadata": { "colab": {}, "colab_type": "code", @@ -801,29 +814,45 @@ "B O \n", "C \n", "Player 1 place:\n", - "Enter your location:b2\n", - "player does not have piece at (1, 1) location. True\n", + "Enter your location:c2\n", + "player does not have piece at (2, 1) location. True\n", "Successfully Placed Player 1! True\n", " 1 2 3 \n", "A X \n", - "B X O \n", - "C \n", + "B O \n", + "C X \n", + "Player 2 place:\n", + "Enter your location:a3\n", + "player does not have piece at (0, 2) location. True\n", + "Successfully Placed Player 2! True\n", + " 1 2 3 \n", + "A X O \n", + "B O \n", + "C X \n", + "Player 1 place:\n", + "Enter your location:a2\n", + "player does not have piece at (0, 1) location. True\n", + "Successfully Placed Player 1! True\n", + " 1 2 3 \n", + "A X X O \n", + "B O \n", + "C X \n", "Player 2 place:\n", "Enter your location:c1\n", "player does not have piece at (2, 0) location. True\n", "Successfully Placed Player 2! True\n", " 1 2 3 \n", - "A X \n", - "B X O \n", - "C O \n", + "A X X O \n", + "B O \n", + "C O X \n", "Player 1 place:\n", - "Enter your location:c3\n", - "player does not have piece at (2, 2) location. True\n", + "Enter your location:b2\n", + "player does not have piece at (1, 1) location. True\n", "Successfully Placed Player 1! True\n", " 1 2 3 \n", - "A X \n", + "A X X O \n", "B X O \n", - "C O X \n", + "C O X \n", "Winner is player: 1 Congratulations!!\n" ] } From 13f8449a340901acaa22faa6ce36dcb149cefb39 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 3 Apr 2020 13:22:14 -0500 Subject: [PATCH 08/12] Mid Exam Submission by Md Arifur Rahman --- Exams/Mid-term/Exam -Submission.ipynb | 700 ++++++++++++++++++++++++++ 1 file changed, 700 insertions(+) create mode 100644 Exams/Mid-term/Exam -Submission.ipynb diff --git a/Exams/Mid-term/Exam -Submission.ipynb b/Exams/Mid-term/Exam -Submission.ipynb new file mode 100644 index 0000000..b5976dd --- /dev/null +++ b/Exams/Mid-term/Exam -Submission.ipynb @@ -0,0 +1,700 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "zk--z4xujTKP" + }, + "source": [ + "# Mid-term 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/Mid-term/Exam.ipynb)\n", + "\n", + "Add cells to this notebook as you need for your solutions and your test of your solutions." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "uTBaYV88jTKS" + }, + "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": 18, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "AZieqqEGjTKU" + }, + "outputs": [], + "source": [ + "states=['Mississippi', 'Maryland', 'Delaware', 'Connecticut', 'Virginia', 'Utah', 'Kansas',\n", + " 'Wyoming', 'Indiana', 'Louisiana', 'Missouri', 'Illinois', 'Minnesota', 'Vermont', \n", + " 'New Mexico', 'North Dakota', 'Wisconsin', 'Tennessee', 'New York', 'Oklahoma', \n", + " 'Colorado', 'Pennsylvania', 'West Virginia', 'Alabama', 'Montana', 'Texas', \n", + " 'Washington', 'Michigan', 'New Hampshire', 'Arkansas', 'Hawaii', 'Iowa', \n", + " 'Idaho', 'Kentucky', 'Ohio', 'Nebraska', 'Alaska', 'Oregon', 'South Dakota', \n", + " 'New Jersey', 'Florida', 'Georgia', 'Rhode Island', 'Arizona', 'Maine', \n", + " 'South Carolina', 'California', 'Nevada', 'Massachusetts', 'North Carolina']" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "OvNMikdfjTKg" + }, + "source": [ + "should return the string `\"Alabama\"`. Note that you can compare strings:" + ] + }, + { + "cell_type": "code", + "execution_count": 0, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "w-flJqbrjTKi" + }, + "outputs": [], + "source": [ + "print(\"A\">\"B\")\n", + "print(\"B\">\"A\")\n", + "print(\"A\">\"a\")\n", + "print(\"bca\">\"bbc\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "j_9y10ddjTKn" + }, + "source": [ + "Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find." + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "def first_alphabetically(lst):\n", + " first_str=lst[0]\n", + " for string in lst:\n", + " if string=bin_edges[i] and d" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "1.01" + ] + }, + "execution_count": 206, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "compute_sigma(generate_normal(100),x90=0.9,mu=0,std=1,n_bins=10)" + ] + }, + { + "cell_type": "code", + "execution_count": 207, + "metadata": {}, + "outputs": [ + { + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAfEAAAEWCAYAAAB2c65HAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4xLjEsIGh0dHA6Ly9tYXRwbG90bGliLm9yZy8QZhcZAAAgAElEQVR4nO3deXhU5fnG8e9DkD0sgiI7KIuyI+AGQhAXwAULBAqKILWiLVpLq6L+ENxwqdVaxSoqohYEBVtRVBRM6oYgmyCbIkY2RUBAAmFJeH5/zIAxZpkkM5lMcn+ua67kzJxz5p6TwJP3Pe95j7k7IiIiEnvKRDuAiIiIFIyKuIiISIxSERcREYlRKuIiIiIxSkVcREQkRqmIi4iIxCgVcZEiYGbjzezfhdh+lZklhDFS1JhZYzNzMyubw+u3m9mzRZ1LJBapiEuJZmZDzGyxmaWa2Xdm9raZdY12rtyY2RQzuzfzc+7eyt2TizBDspldU1Tvl5m7T3D3PN87mhlFigsVcSmxzGw08A9gAlAbaAg8CfSNZi4p/nLqJRApblTEpUQys2rA3cAf3f01d9/n7ofd/Q13vzm4zi9avGaWYGabMy2nmNnNZrbCzPaZ2XNmVjvYmt9rZvPMrEZ222ba/vwc8r1qZt+b2R4z+8DMWgWfvxa4Argl2HvwRuZ9mVldM0szs+Mz7auDme0ws+OCyyPMbI2Z7TKzuWbWKIcMFczs32a208x2m9lnwc93H3Au8EQwwxPB9U81s/fM7EczW2dmAzPta4qZPRV8fa+Z/S+n983kCjPbGMx+R6Z9HTv1UICM5wTX2RP8ek6m/TYJHuujP7uJmd7naBf/78xsI/B+bj+nTJ/5yeDvQ6qZfWxmJ5nZP4LHfq2Zdci0/q1mtiX4/uvMrGcex0ckTyriUlKdDVQA/lPI/fQHLgCaA5cCbwO3A7UI/Pu5sYD7fRtoBpwILAWmArj7pOD3D7l7FXe/NPNG7r4VWBDMddQQYKa7Hzazy4P5+gEnAB8CL+eQYRhQDWgA1ASuA9Lc/Y7gdqOCGUaZWWXgPWBaMPNg4MnMRY3AHx/3EDg2y49+plx0BVoAPYE7zey0QmY8HpgD/DO47iPAHDOrGdzXNGBR8LXxwNBs3q87cBpwUXA5259TJgOB/wt+5oMEfjZLg8szgxkwsxbAKKCzu8cH95+Sx/ERyZOKuJRUNYEd7p5eyP087u7b3H0LgaKx0N2XuftBAn8gdMh98+y5+2R33xvcz3igXbD3IBTTCBRRzMyA3wafAxgJ3O/ua4KffQLQPodW8WECx6mpu2e4+xJ3/ymH97wESHH359093d2XArOAAZnWmePuHwQ/0x3A2WbWIJfPcZe7p7n758DnQLtCZrwY+MrdXwpmfBlYC1xqZg2BzsCd7n7I3T8CZmezj/HBXps0COnn9J9gpgMEfh8OuPuL7p4BzODn348MoDzQ0syOc/cUd/86l2MjEhIVcSmpdgK1wnBuc1um79OyWa6S3x2aWZyZPWBmX5vZT/zcIqsV4i5mEiiQdYFugBP4AwOgEfBYsOt5N/AjYEC9bPbzEjAXmG5mW83soaNd8tloBJx5dL/BfV8BnJRpnU1Hv3H31OB7183lc3yf6fv9ZH8s85OxLvBtlue+JfDZ6wI/uvv+7PJm91yIP6eQfj/cfT1wE4E/BH4ws+nBn59IoaiIS0m1ADgAXJ7LOvuASpmWT8ppxRD8Yl9mFkegOzs7QwgMrjufQFdx46ObBb/memtBd98NvEugK3cI8LL/fDvCTcBId6+e6VHR3T/JZj+H3f0ud28JnEOgtX1VDhk2Af/Lst8q7n59pnWOtbrNrApwPLA1t8+Sl3xm3Ergj43MGgJbgO+A480s8887u16CzPvM6+eUL+4+zd27BjM68GBB9iOSmYq4lEjuvge4E5hoZpebWSUzO87MepvZQ8HVlgN9zOx4MzuJQEupoL4EKpjZxcGW4v8R6D7NTjyB86c7CRT+CVle3wacnMf7TSNQzPrzc1c6wFPAbfbzQLlqZpaY3Q7MrIeZtQn+wfETga7rjBwyvAk0N7OhweN4nJl1znIeu4+ZdTWzcgTOjS909+xauyHLZ8a3ghmHmFlZMxsEtATedPdvgcXAeDMrZ2ZnExjjkJu8fk75+RwtzOw8MytP4I/LtEyfQ6TAVMSlxHL3R4DRBArqdgKtyVHAf4OrvETgXGwKgZbtjEK81x7gD8CzBFp++4DNOaz+IoFu3i3AauDTLK8/R+Dc6W4z+2/WjYNmExhwtS14Tvlojv8QaOFND3YBfwH0zmEfJxHomv8JWAP8Dzg6Ic1jwIDgKOt/uvte4EIC59+3EugKf5Bf/qEyDRhHoBu9I4Hu9sLKT8adBFrqfyFQeG8BLnH3HcH1ryAw4HEncC+Bn/fBXN47r59TfpQHHgB2EDh2JxIYgChSKPZzL5yISMGY2RRgs7v/X7SzhMrMZgBr3X1ctLOIFJRa4iJSKgS7/08xszJm1ovA+e6cejpEYoJmJRKR0uIk4DUCl6xtBq5392XRjSRSOOpOFxERiVHqThcREYlRMdedXqtWLW/cuHG0Y+Ro3759VK5cOdoxSgwdz/DS8Qw/HdPw0vH8tSVLluxw92znnYi5It64cWMWL14c7Rg5Sk5OJiEhIdoxSgwdz/DS8Qw/HdPw0vH8NTPLOhPhMepOFxERiVEq4iIiIjFKRVxERCRGqYiLiIjEKBVxERGRGKUiLiIiEqMiVsTNbLKZ/WBmX+TwupnZP81svZmtMLPTI5VFRESkJIpkS3wK0CuX13sTuJViM+Ba4F8RzCIiIhJx6enpHDlypMjeL2KTvbj7B2bWOJdV+gIvemDy9k/NrLqZ1XH37yKVSURE5KiDBw+ye/duypUrR40aNUhLS+Ptt9/mp59+Yu/evccevXr1onv37mzatImRI0eyf//+Y499+/YxYcIEBg8ezKJFizjzzDNZsWIFbdq0KZLPEM0Z2+oBmzItbw4+96sibmbXEmitU7t2bZKTk4siX4GkpqYW63yxRsczvHQ8w0/HNLwKczzdnTVr1rB79252797Nnj172LNnD6eeeioJCQkcOHCA66+/nr1795KamsrBgwcBGDp0KCNGjGDXrl3079//F/uMi4vjp59+wt3Zvn07X3/9NRUqVKBixYrUrFmTevXq8dnqDeyY+jp7dv1In/6DefujpezcubOwhyIk0Szils1z2d5Szd0nAZMAOnXq5MV5Sj5NGRheOp7hpeMZfjqm4ZX1eKalpbF3715OPPFEAP7xj3+wYcMGvvvuu2OP888/n6effhp35+KLLyYtLe3Y9hUqVKBevXokJCTg7nTs2JHq1atTo0YNqlevTvXq1TnzzDPp1KkTGRkZLFu2jKpVqxIfH098fDzly5fH7OdylZiY+KvMjcfMIeWKiwMLo66m8Zg53HJ9wq/Wi4RoFvHNQINMy/WBrVHKIiIiEdDlgffZsjstx9c9/TAZaXsoG18LgLYpr3DxyDtI/2k76T/9wJH9eyjfsC0nDZ4AwJZnHiYjdRdxVY4PPhow89tyzB0zB4CqfcdSrVxF4ipVpUzFathx5Zllxqzg6zS9+uc33xt8bNoGM+dkSrUlX5+xXvWK+Vo/nKJZxGcDo8xsOnAmsEfnw0VESpYtu9P45v4+x1qzM2fOJCkpia+++oovv/ySTRs30rRpU7788ksAunSZQAPbSaO2TWjUKIFGjRrRunVr+vYNtHQP3vU15cuXz+UdL470RypWIlbEzexlIAGoZWabgXHAcQDu/hTwFtAHWA/sB67Ofk8iIlJU8mo55yVj/x4Obfuaw9tTOLT9W9i1iTpTfsfWrVspU6YM77zzDjNnzqR58+Z07dqVpk2bcuqppx7b/r777sv19ETuBbz0ieTo9MF5vO7AHyP1/iIikn9bdqeR8kDerVl3JyUlhcWLF7N06VLGjBlDtWrVGDduHHc/fjcAJ510Eq1bt6Zly5YcOHCASpUqMXHiRJ555plfnGeWgou5+4mLiEj4ZG1553V+d9GiRYwfP55FixYdG4FdtmxZ+vXrR+fOnbnyyitJSEigTZs21KpV61fbqyUdXiriIiKlWE4t702bNvG///2PDz/8kE8++YRx48YxYMAAzIxNmzbRt29fOnfuTKdOnWjdujUVKlQAoFmzZjRr1qyoP0appSIuIiKkp6dTtmxZduzYwRlnnME333wDQLVq1Tj77LOJj48HoHPnzqxcuTKaUSUTFXERkVIoLS2N5ORkfpz/DK1b30rHjh154YUXqFmzJgkJCfzpT3+ie/futGnThri4uGjHlRyoiIuIxLCCjCbfOXci+76Yj6cfokzZctTt0Z0uXboAYGZMnjw5ElElAlTERURiWG6jyd2d5cuX89///pcPPviAefPmERcXx/3VVvB9t2b06dOHbt26UbFi9CYrkcJRERcRKWHWr1/PpEmTePXVV0lJScHM6Nq1Kz/88AN16tThtttui3ZECZNI3opURESKyMqVK9m4cSMAKSkpPProo7Rs2ZJnn32W77//ng8++IA6depEOaWEm1riIiLFWG7nvNP37qDsN5/Qrt3trFixgr/85S88/PDDJCQk8MMPP1CjRo0iTitFTUVcRKQYy+6ct7szcOBAXnvtNY4cOcJZZ53FE088wcCBA4HA5Csq4KWDiriISAxYu3Yts2fP5pZbbsHMOOWUU7jtttsYNmyYJlcpxVTERUSKqcOHD7Nv7Uecd97fSUpK4rjjjmPgwIE0btyYBx54INrxpBhQERcRiZLczncf/H4922feRca+XWxo1IgJEyYwYsQIateuXcQppThTERcRiZKs57tXrlzJjh076NGjB/v27WNY6ocMHz6c3r17a9Y0yZaKuIhIhOQ1m1q96hVxd5KSknjwwQd599136dChA0uXLqVy5crMnDmzCNNKLFIRFxGJkLzuzf3+++9zxhlnsHjxYmrXrs2ECRMYOXJkESaUWKciLiJShDIyMjh8+DAVKlRgx44d7Nq1i6eeeophw4Ydu52nSKg0Y5uISBFIT0/npZdeomXLlvztb38DoH///qxbt46RI0eqgEuBqIiLiETQkSNHeOWVV2jdujVXXXUVFSpUoEOHDgDExcVpwJoUirrTRURClN1Atb+0SWf4mDnZrl+vekVuuOEGnnzySVq2bMmsWbO4/PLLKVNG7ScJDxVxEZEQZTdQLTk5mZQrEn7x3KJFi6hXrx716tVj6dLqnH322QwePFitbgk7FXERKbXyugQsq3rVc7/v9oYNG7j99tuZMWMGo0aN4vHHH+f000/n9NNPL2xUkWypiItIqZXXJWCh2rNnD/feey+PPfYYxx13HGPHjuXmm28OQ0KR3KmIi4gU0h133MGTTz7J8OHDuffee6lbt260I0kpoSIuIlIACxYsID4+HggU8eHDh9OpU6cop5LSRkMkRUTyYceOHVxzzTWcc8453H333QDUqVNHBVyiQkVcRCQER44cYdKkSbRo0YIXXniBm2++mcmTJ0c7lpRy6k4XkRIrlBuQhOqpp57ij3/8I926dePJJ5+kVatW4YgoUigq4iJSYhV29PnBgwdJSUmhRYsWXH311dSsWZOBAwdiZmFMKVJwKuIiUmJkbXnnp6Wd1ccff8w111zDgQMHWLduHRUrVmTQoEHhiCkSNiriIlJihOO67/3793PHHXfw2GOP0bBhQ55++mnKlSsXpoQi4aUiLiIStGXLFhISEli/fj1/+MMfePDBB6lSpUq0Y4nkKKKj082sl5mtM7P1ZjYmm9cbmlmSmS0zsxVm1ieSeUREclOnTh26dOnC+++/z8SJE1XApdjLsyVuZrWBCUBdd+9tZi2Bs939uTy2iwMmAhcAm4HPzGy2u6/OtNr/Aa+4+7+C+30LaFywjyIipU04zoEvW7aMP/3pT0yfPp26desyZcqUMCYUiaxQutOnAM8DdwSXvwRmALkWceAMYL27bwAws+lAXyBzEXegavD7asDWkFKLiFC4c+AZGRk89NBDjBs3jlq1arFp0yZNlyoxx9w99xXMPnP3zma2zN07BJ9b7u7t89huANDL3a8JLg8FznT3UZnWqQO8C9QAKgPnu/uSbPZ1LXAtQO3atTtOnz49P5+xSKWmpqoLLox0PMMr1o/nuu/3cijjyLHlcnFlaHFSfL738/333zNhwgRWrlxJQkICf/7zn6latWreG2Yj1o9pcVMSjufKLXtoU69a2PbXo0ePJe6e7ZSAobTE95lZTQKtZszsLGBPCNtldyFl1r8YBgNT3P3vZnY28JKZtXb3I7/YyH0SMAmgU6dOnpCQEMLbR0dycjLFOV+s0fEMr1g/nsPHzCHlgUsLvZ9rrrmGlJQUXnrpJa644opCXfcd68e0uCkJx3P4mDm/usd8pIRSxEcDs4FTzOxj4ARgQAjbbQYaZFquz6+7y38H9AJw9wVmVgGoBfwQwv5FpIQL53Xf+/bt48cff6RBgwY8/PDD3HbbbZxyyinhiCkSNXkWcXdfambdgRYEWtfr3P1wCPv+DGhmZk2ALcBvgSFZ1tkI9ASmmNlpQAVgez7yi0gJFq77fX/xxRckJiZSuXJlFi1aRPXq1alevXoYEopEVyij0/8ITHX3VcHlGmY22N2fzG07d083s1HAXCAOmOzuq8zsbmCxu88G/gI8Y2Z/JtDVPtzzOkkvIiVWOFveAO7O5MmTueGGG6hWrRoTJ06kTBnd90lKjlC603/v7hOPLrj7LjP7PZBrEQ+u+xaBy8YyP3dnpu9XA11CjysiJVm4Wt4Q6D6/7rrr+Pe//03Pnj2ZOnUqtWvXDsu+RYqLUP4kLWOZRn0Er//WHIQiUqyVKVOGL774grvuuou5c+eqgEuJFEpLfC7wipk9RaDL+zrgnYimEhEpoDfeeIOEhATi4+NZuHCh5j2XEi2UIn4rMBK4nsDAtneBZyMZSkRKh3CeAz98+DC33norjz76KOPGjWP8+PEq4FLihTI6/Qjwr+BDRCRswnUOfNu2bSQmJvLhhx9yww03cPvtt4chnUjxF8ro9C7AeKBRcH0D3N1Pjmw0EZG8LV++nEsuuYQff/yRqVOnMmRI1itZRUquULrTnwP+DCwBMiIbR0Qkf2rUqEGdOnV48803ad8+19mgRUqcUEan73H3t939B3ffefQR8WQiIjlIT0/n2Wef5ciRIzRq1IhFixapgEupFEpLPMnM/ga8Bhw8+qS7L41YKhEpkcIxkG3Xrl0MHDiQefPm0aBBAy666KJCzX0uEstCKeJnBr9mvoOKA+eFP46IlGSFHci2du1aLrvsMlJSUpg8eTIXXXRRGNOJxJ5QRqf3KIogIiK5ee+990hMTKRcuXIkJSXRpYsmexTJ85y4mdU2s+fM7O3gcksz+13ko4mI/Kx8+fI0a9aMzz77TAVcJCiUgW1TCMzaVje4/CVwU6QCiYgclZGRwbvvvgtAt27dWLhwIY0aNYpyKpHiI5QiXsvdXwGOQODuZOhSMxGJsL1799K3b18uuugili1bBqA7kIlkEcrAtn1mVpPAYDbM7CxgT0RTiUiptnnzZi655BK++OILnnzySTp06BDtSCLFUihFfDQwGzjFzD4GTgAGRDSViJRaK1asoE+fPvz000/MmTNHI9BFcpFrETezMkAFoDvQgsCUq+vc/XARZBORGJb1mnAI7brwhQsXAvDhhx/Srl27iGQTKSlyLeLufsTM/u7uZwOriiiTiJQA+b0mfMuWLdSrV4/f//73DBo0iKpVq0YwnUjJEMookXfNrL9pSiQRiQB3595776V58+asWhVoK6iAi4Qm1HPilYF0MzvAz3cx078yESmUjIwMRo0axVNPPcXQoUNp1qxZtCOJxJS8zokb0MrdNxZRHhEpJdLS0hg8eDCvv/46Y8aMYcKECZoDXSSfcu1Od3cH/lNEWUSkFJk4cSKzZ8/m8ccf5/7771cBFymAULrTPzWzzu7+WcTTiEjMyu8dym666SbOOOMMunXrFuloIiVWKEW8BzDSzL4F9vHzOfG2EU0mIjEllNHo69atY+TIkUybNo26deuqgIsUUihFvHfEU4hIibd48WJ69+6NmbF9+3bq1q2b90YikqtQLjHzHB4iIiGZP38+PXr0oEqVKnz88ceaxEUkTEJpic8hULSNwOxtTYB1QKsI5hKRYia7Gdgyy+kc+Pz58+nTpw/Nmzdn7ty5aoGLhFGeRdzd22ReNrPTgZERSyQixVJ+Z2A7qkOHDlxxxRU8/PDDHH/88RFIJlJ65fu+fu6+FOgcgSwiUoLMnDmTAwcOcPzxxzN58mQVcJEIyLOIm9noTI+/mtk0YHsRZBORGOTu3HXXXSQmJvLkk09GO45IiRbKOfH4TN+nEzhHPisycUQklrk7f/3rX3nkkUcYPnw4N954Y7QjiZRooZwTv6sogohIbMvIyOC6667j2Wef5cYbb+TRRx+lTJl8n7ETkXzIs4ib2XtAorvvDi7XAKa7+0WRDiciRaego8+P2rhxI7NmzeKOO+7gnnvu0TSqIkUglO70E44WcAB332VmJ4ayczPrBTwGxAHPuvsD2awzEBhP4DK2z919SCj7FpHwKujo8/T0dOLi4mjSpAmrVq2iTp06EUgnItkJpYhnmFnDo3cyM7NGhDDZi5nFAROBC4DNwGdmNtvdV2dapxlwG9AlP38ciEjh5Xeu8+zs37+f3/zmN3Tt2pWxY8eqgIsUsVCK+B3AR2b2v+ByN+DaELY7A1jv7hsAzGw60BdYnWmd3wMT3X0XgLv/EGpwESmcgra8j9q7dy+XXnopH3zwAYMGDQpjMhEJVSgD294JTvByFoFZ2/7s7jtC2Hc9YFOm5c3AmVnWaQ5gZh8T6HIf7+7vhBJcRKJn9+7d9O7dm88++4ypU6cyePDgaEeSCDl8+DCbN2/mwIEDRfJ+1apVY82aNUXyXpHyzGV1CvQZKlSoQP369TnuuONC3sYCtwzPZQWz3wDvu/ue4HJ1IMHd/5vHdonARe5+TXB5KHCGu9+QaZ03gcPAQKA+8CHQOvM5+OB61xJs/deuXbvj9OnTQ/6ARS01NZUqVapEO0aJoeMZXpmP58ote2hTr1q+95GRkcGoUaNYv349d955J+eee264Y8aUkv47WqVKFWrXrk21atWKZLBiRkYGcXFxEX+fSNp/KINK5fL3GdydPXv2sG3bNlJTU3/xWo8ePZa4e6fstgulO32cu/8n0xvtNrNxQK5FnEDLu0Gm5frA1mzW+dTdDwPfmNk6oBnwi3uXu/skYBJAp06dPCEhIYTY0ZGcnExxzhdrdDzDK/PxHD5mDilXJBRoP7fddhu1atWiT58+4QsXo0r67+iaNWuoX79+kV1tsHfvXuLj4/NesRj7ZvNu2tbM/2eIj48nNTWVTp2yrdfZCuUizuzWCaX4fwY0M7MmZlYO+C0wO8s6/yVwv3LMrBaB7vUNIexbRIrYd999x/z58wG46qqrVMBLEV0uWDQKcpxDKeKLzewRMzvFzE42s0eBJXlt5O7pwChgLrAGeMXdV5nZ3WZ2WXC1ucBOM1sNJAE3u/vOfH8KEYmozZs30717dwYNGsTevXujHUdKkZ07d9K+fXvat2/PSSedRL169Wjfvj3Vq1enZcuWRZpl+fLlvPXWW8eWZ8+ezQMP/OrK6ZA0btyYHTtCGV6Wu1Ba1DcAY4EZBAa2vQv8MZSdu/tbwFtZnrsz0/cOjA4+RKQY2rhxIz169GD79u28/fbbMd/VKbGlZs2aLF++HIDx48dTpUoV/vrXv5KSksIll1wS9vdLT0+nbNnsS+Py5ctZvHjxsV6oyy67jMsuuyzbdYtKni1xd9/n7mOA84Du7n6bu++LfDQRibaUlBS6d+/Ozp07ee+99+jSpUu0I4kck5GRwe9//3tatWrFhRdeSFpaYN6Dr7/+ml69etGxY0fOPfdc1q5dC8C3335Lz549adu2LT179mTjxo0ADB8+nNGjR9OjRw9uvfVW9u3bx4gRI+jcuTMdOnTg9ddf59ChQ9x5553MmDGD9u3bM2PGDKZMmcKoUaMA2LZtG7/5zW9o164diRd25ZNPPgHg8ssvp2PHjrRq1YpJkyaF/RiEMu1qG+BF4Pjg8g5gmLt/EfY0IlKsTJ48mT179jBv3rx8DbaRkiu7QXwDBw7kD3/4A/v37892rMTw4cMZPnw4O3bsYMCAAb94LTk5ucBZvvrqK15++WWeeeYZBg4cyKxZs7jyyiu59tpreeqpp2jWrBkLFy7kD3/4A++//z6jRo3iqquuYtiwYUyePJkbb7yR//43MEb7yy+/ZN68ecTFxXH77bdz3nnnMXnyZHbv3s0ZZ5zB+eefz913383ixYt54oknAJgyZcqxLDfeeCPdu3fnP//5D8u+3cnJ1QPl9ehteNPS0ujcuTP9+/enZs2aBf7MWYXSnf40MNrdkwDMLIHASPFzwpZCRIoVd8fMGD9+PCNGjKBx48bRjiTyK02aNKF9+/YAdOzYkZSUFFJTU/nkk09ITEw8tt7BgwcBWLBgAa+99hoAQ4cO5ZZbbjm2TmJi4rFL2959911mz57Nww8/DMCBAweOtdpz8v777/Piiy8CEBcXR7Vqgcs3//nPf/Kf/wQu8Nq0aRNfffVVkRfxykcLOIC7J5tZ5bAlEJGwyOsGJgB/aZPO8DFzgJynWV23bh3Dhw9n6tSpnHzyySrg8gu5tZwrVaqU6+u1atUqVMs7q/Llyx/7Pi4ujrS0NI4cOUL16tWPnUfPTebR4JUr/1zW3J1Zs2bRokWLX6y/cOHCfOVLTk5m3rx5LFiwgEqVKpGQkBD2SXNCKeIbzGws8FJw+Urgm7CmEJFCC2Ua1eTk5FyvDV+zZg3nnXceR44cOXZ+USSWVK1alSZNmvDqq6+SmJiIu7NixQratWvHOeecw/Tp0xk6dChTp06la9eu2e7joosu4vHHH+fxxx/HzFi2bBkdOnQgPj4+x6szevbsyb/+9S9uuukmMjIy+Omnn9izZw81atSgUqVKrF27lk8//TTsnzeUS8xGACcArwUftYCrw55ERPKlywPv03jMnDj5y50AAB1ZSURBVGOPgtzAJLPVq1fTo0cP3J2kpCRatWoVpqQiRWvq1Kk899xztGvXjlatWvH6668Dga7t559/nrZt2/LSSy/x2GOPZbv92LFjOXz4MG3btqV169aMHTsWgB49erB69epjA9sye+yxx0hKSqJNmzYM7pPAqlWr6NWrF+np6bRt25axY8dy1llnhf2z5jntanHTqVMnX7x4cbRj5Kikz95U1HQ8c9Z4zJx838Akp+O5du1aunXrRlxcHElJSZx66qlhSlnylfTf0TVr1nDaaacV2fuVhBnbVmzeTdv61Qu0bXbH28xynHY1lJa4iJRwderUoUuXLiQnJ6uAi8SQUM6Ji0gJtW7dOho0aEC1atWOjaAVkdiRY0vczB4Mfk3MaR0RiV2ff/45Xbp04frrr492FBEpoNy60/uY2XHAbUUVRkSKxvLly+nZsycVK1bkzjvvzHsDESmWcutOfwfYAVQ2s58IzJvuR7+6e9UiyCciQVmvAy/oaPRly5Zx/vnnU7lyZZKSkjjllFPCFVFEiliORdzdbwZuNrPX3b1vEWYSkWyEch14XjIyMhgyZAhVqlQhKSmJk08+OUzpRCQaQrkBSl8zq21mlwQfJxRFMBEJv7i4OF599VUVcIkpcXFxx25H2r59+wLf/jOrPn36sHv37ny/lpspU6Yw4f9uLmy0kIVyA5RE4GEgmUBX+uNmdrO7z4xwNhEJk6VLl/LWW2/RpUsXWrduHe04EsNCmd43P+pVr8jHY87LdZ2KFSuGNI1qfmW+N/hR7o67Z/tacRTKJWb/B3R29x8Agi3xeYCKuEgMWLp0Keeffz5Vq1albdu20Y4jMS4cp3Uyaxycy79A2zZuzJAhQ0hKSuLw4cNMmjSJ2267jfXr13PzzTdz3XXXkZyczJ133knNmjVZt24d3bp148knn6RMmTI0btyYxYsXk5qaSu/evenRowcLFizgv//9L927d2fx4sXUqlWLF198kYcffhgzOzbb2xtvvMG9997LoUOHqFmzJlOnTqV27dphOy6hCmWylzJHC3jQzhC3E5EoW7JkCT179qRq1aokJydTtarGo0rsSUtL+0V3euYpTxs0aMCCBQs499xzGT58ODNnzuTTTz/9xVUXixYt4u9//zsrV67k66+/PnYns8zWrVvHVVddxbJly2jUqNGx51etWsV9993H+++/z+eff35sqtauXbvy6aefsmzZMn7729/y0EMPRfAI5CyUlvg7ZjYXeDm4PAiIjX4GkRhW2NHoS5Ys4fzzz6d69eokJSXRuHFjUlJSwpxSJPJy606/7LLLAGjTpg2pqanEx8cTHx9PhQoVjp3TPuOMM46NARk8eDAfffTRr+5r3qhRo2znNn///fcZMGAAtWrVAuD4448HYPPmzQwaNIjvvvuOQ4cO0aRJk/B82HzKs4i7+81m1g/oSuCc+CR319ROIhFW2G7LDRs2ULNmTebNm6fbiUqJdfR2pGXKlPnFrUnLlClDeno68Mtbjma3DL+8FWlm7p7t+jfccAOjR4/msssuIzk5mfHjxxf0IxRKSN3i7v6au4929z+rgIsUb6mpqQAkJiayatUqFXAp9RYtWsQ333zDkSNHmDFjRo63IM1Oz549eeWVV9i5cycAP/74IwB79uyhXr16ALzwwgvhDx0indsWKUEWLVrEySefzNtvvw3wi5aJSKzKek58zJgx+dr+7LPPZsyYMbRu3ZomTZrwm9/8JuRtW7VqxR133EH37t1p164do0ePBmD8+PEkJiZy7rnnHutqjwbdAEWkhFi0aBEXXHABNWvW1L3AJWLqVa9YqBHl2e0vLxkZGdk+n3mMx/Dhwxk+fHi2r1WqVOlX9//OvE6tWrX44osvctz3sGHDGDZs2C9e79u3L337/noetOHDh3P6+Zfn8EnCT0VcpARYuHAhF154IbVq1SIpKYmGDRtGO5KUUHld0y1FK8cibmYrCcyVni131wWnIsXAhg0buOCCCzjxxBNJSkqiQYMG0Y4kUmwkJCSQkJAQ7RgRk1tL/JLg1z8Gv74U/HoFsD9iiURKqYJeUtakSRNuvfVWhg0bRv369SMVT0SKodxugPItgJl1cfcumV4aY2YfA3dHOpxIaZLfS8o++eQTatWqRfPmzbnjjjsimExKu5wus5Lwcs+x8ztHoZwTr2xmXd39IwAzOwfI/oI6EQlZYSZz+fDDD+nduzdnnnkm8+fPj0Q8EQAqVKjAzp07qVmzpgp5BLk7O3fupEKFCvnaLpQi/jtgsplVCy7vBkbkM5+IZFHQyVySk5O5+OKLadiwIf/+978jkEzkZ/Xr12fz5s1s3769SN7vwIED+S5kxc22XWms2Zu/GRYh8AdTfk+JhTJj2xKgnZlVBczd9+Q7mUgplNfdnvI7jSrA/PnzufTSS2nSpAnz58/npJNOKkxEkTwdd9xxRTqlaHJyMh06dCiy94uE3mPmhPUmMbkJ5Vak1YBxQLfg8v+Au1XMRXIX7rs9uTsPPvggTZs2Zd68eZx44olh27eIxKZQutMnA18AA4PLQ4HngX6RCiUiv3R0YNGsWbM4ePBgVGeIEpHiI5RpV09x93HuviH4uAs4OdLBRCTgjTfe4KKLLmLfvn3Ex8ergIvIMaEU8TQzOzZbvJl1AXI+0SciYfPaa6/Rr18/du/ezaFDh6IdR0SKmVCK+PXARDNLMbNvgSeAkaHs3Mx6mdk6M1tvZjnOWG9mA8zMzaxTaLFFSr4ZM2YwcOBAOnfuzHvvvUeNGjWiHUlEiplQRqcv5+fR6bj7T6Hs2MzigInABcBm4DMzm+3uq7OsFw/cCCzMZ3aRYiO7kegFGX1+1CuvvMKQIUPo2rUrb775JvHx8YWNKCIlUCRHp58BrHf3DcHtpgN9gdVZ1rsHeAj4a/6iixQf4R6J3rZtWwYNGsQzzzxD5cqaW0lEsmd5TfNmZrMIjE4/etfzoUA7d891dLqZDQB6ufs1weWhwJnuPirTOh2A/3P3/maWDPzV3Rdns69rgWsBateu3XH69Okhfryil5qaSpUqVaIdo8SIleO5csse2tSrlveKefj8889p27ZtxGbGipXjGUt0TMOrJBzPcP1/cFSPHj2WuHv2p5vdPdcHsDyU57JZJxF4NtPyUODxTMtlgGSgcXA5GeiU1347duzoxVlSUlK0I5QosXI8G936ZqH38dBDDzngL7zwQhgSZS9Wjmcs0TENr5JwPMPx/0FmwGLPoSZGcnT6ZiDzPRHrA1szLccDrYFkM0sBzgJma3CblDbuzj333MMtt9zCoEGDGDx4cLQjiUiMCGWyl+uAF4Pnxg34ERgewnafAc3MrAmwBfgtMOToix44p37sgtfcutNFSip3Z8yYMTz00EMMGzaM5557jri4uGjHEpEYEcro9M8pwOh0d083s1HAXCAOmOzuq8zsbgJdA7MLkVukRFi5ciWPPPII119/PU888QRlyoTSOSYiEhDK6PTyQH+gMVD26IAbd8/zfuLu/hbwVpbn7sxh3YQ804qUMG3btuWzzz6jXbt2us2jiORbKN3prwN7gCXAwcjGEYkNhbkX+KFDhxg2bBj9+vUjMTGR9u3bRyKiiJQCoRTx+u7eK+JJRGJIQa8L379/P/379+edd97hzDPPjEAyESlNQinin5hZG3dfGfE0IsVUYVreR+3evZtLLrmEBQsW8Oyzz/K73/0unBFFpBTKsYib2UrAg+tcbWYbCHSnG+Du3rZoIopEX2FnZNu3bx89evRg1apVTJ8+ncTExDCmE5HSKreW+CVFlkKkhKtUqRIXX3wx999/P7166eyUiIRHbkV8l7v/ZGbHF1kakRJmzZo1HD58mLZt23LvvfdGO46IlDC5FfFpBFrjSwh0q2e+/sWBkyOYSySqwnEOfNGiRfTp04eGDRuyZMkSXUImImGXYxF390uCX5sUXRyR4qGw58DnzZvH5ZdfTu3atXn11VdVwEUkInIb2HZ6bhu6+9LwxxGJfTNmzGDo0KGcdtppvPPOO9SpUyfakUSkhMqtO/3vubzmwHlhziIS89yd559/nrPOOovZs2dTvXr1aEcSkRIst+70HkUZRCSWuTupqanEx8czc+ZMypYtS4UKFaIdS0RKuFDmTq8EjAYauvu1ZtYMaOHub0Y8nUgRKcxAtsOHD3PNNdewZs0aPvjgA6pUqRKJiCIivxLKjG3PExihfk5weTPwKqAiLiVGQQey7d27l8TERObOnctdd91F+fLlI5BORCR7oRTxU9x9kJkNBnD3NNNQWxG2bt3KxRdfzMqVKzWNqohERShF/JCZVSQwmA0zOwXdzUyEYcOG8dVXX/HGG2/Qu3fvaMcRkVIolCI+DngHaGBmU4EuwPBIhhIJt6znvLMqyGQuTz31FHv27OH003O9GlNEJGLyLOLu/p6ZLQXOIjBr25/cfUfEk4mEUWEnbznqxRdf5IMPPuCZZ57hlFNOCUMyEZGCC2V0+t3uficwJ7hcxsymuvsVEU8nUkDhmDY1M3dn/Pjx3H333Zx33nmkpaVRqVKlwsYUESmUULrTG5rZbe5+v5mVJzAyXbO1SbEWrpY3wMGDBxkxYgTTpk1jxIgR/Otf/6JcuXJh2beISGGEUsSvBqaa2W1AD+Btd380srFE8ifcLe/M+vfvz5w5c5gwYQJjxozRPOgiUmyEOnf6Y8DTwMfA/8zsdM2dLsVJOFveWf3pT39i2LBhJCYmRmT/IiIFlZ+503cBLYPPa+50KdHeeOMNvvnmG2688UYuuOCCaMcREcmW5k4XycTd+dvf/saYMWPo3Lkz119/Pccdd1y0Y4mIZCu37vQr3f3fZjY6u9fd/ZHIxRIpevv37+eaa67h5ZdfZuDAgTz//PMq4CJSrOXWnV45+DU+m9c8AllEoiY9PZ2EhAQWL16sAWwiEjNy605/Ovj1rqyvmdlNkQwlkpdwj0YvW7YsV199NePGjePiiyMzQE5EJNxCucQsO6OBf4QziEh+hGM0urvz2GOP0bRpUy655BKuv/76MKUTESkaZQq4nfoZJabt27ePIUOG8Oc//5lZs2ZFO46ISIEUtIjrnLjErK+++oqzzjqLV155hfvvv5/JkydHO5KISIHkNjp9L9kXawPCNx2WSAjCdQ78m2++oWPHjpQrV4533nlH14CLSEzLbWBbdqPSRaIiXDOyNW7cmDFjxnDllVfSsGHDMCQTEYmegnani8SMlJQUevbsydq1azEzbr/9dhVwESkRIlrEzayXma0zs/VmNiab10eb2WozW2Fm882sUSTzSOkza9Ys2rdvz+LFi9m4cWO044iIhFXEiriZxQETgd4E5lwfbGYts6y2DOjk7m2BmcBDkcojpUtaWhrXXXcdAwYMoEWLFixbtowLL7ww2rFERMIqki3xM4D17r7B3Q8B04G+mVdw9yR33x9c/BSoH8E8Uoo8+uijPP3009xyyy189NFHnHzyydGOJCISduYemavFzGwA0MvdrwkuDwXOdPdROaz/BPC9u9+bzWvXAtcC1K5du+P06dMjkjkcUlNTqVKlSrRjxLx13+/lUMYRaleEbWlQLq4MLU7KfazlkSNH2LlzJyeccAKHDh1i9erVtG/fvogSxwb9foafjml4lYTjuXLLHtrUqxa2/fXo0WOJu3fK9kV3j8gDSASezbQ8FHg8h3WvJNASL5/Xfjt27OjFWVJSUrQjlAiNbn3T3UM/nlu2bPELL7zQmzRp4nv37o1gstim38/w0zENr5JwPI/+/xUuwGLPoSYWdNrVUGwGGmRarg9szbqSmZ0P3AF0d/eDEcwjJdRrr73Gtddey/79+3nkkUeoXLly3huJiJQAkTwn/hnQzMyamFk54LfA7MwrmFkH4GngMnf/IYJZpATat28fV1xxBf3796dx48YsW7aM6667TncfE5FSI2JF3N3TgVHAXGAN8Iq7rzKzu83ssuBqfwOqAK+a2XIzm53D7kR+pWLFimzbto27776bBQsW0KJFi2hHEhEpUpHsTsfd3wLeyvLcnZm+Pz+S7y/FV9ZpVLPKaVrVH3/8kbFjxzJ27FhOOukk3n33XcqU0ZxFIlI6RbSIi+Qkv9OoujszZ87khhtuYMeOHXTt2pXBgwergItIqab/AaXY27p1K/369WPgwIHUq1ePxYsXM3jw4GjHEhGJOhVxKfbGjRvHO++8w0MPPcTChQt17beISJC606VI5PdWokuWLKFixcA69913H7feeitNmzaNaEYRkVijIi5FItRz4Lt27WLcuHFMnDiRSy+9lJtuuokTTzyRE088sQhSiojEFnWnS7GQkZHBs88+S/PmzXniiSe47rrrmDJlSrRjiYgUayriUixMmjSJ3//+95x66qksWbKEiRMnUr169WjHEhEp1tSdLhERyjnwb775hu+//56zzz6b4cOHU6tWLQYMGKAZ10REQqQiLhGR2znw3bt3M2HCBB577DGaN2/OihUrqFixIomJiUWcUkQktqk7XYrMgQMHePTRR2natCkPP/wwgwcP5u2331bLW0SkgFTEpci8+eabjB49mtNPP53FixczZcoU6tevH+1YIiIxS93pEjEZGRm88sorHDhwgKuvvpp+/frx0Ucf0aVLl2hHExEpEdQSl7DLyMhg3+r/0aZNG4YMGcLkyZNxd8qUKaMCLiISRmqJS77ldgeyA9+u4Mf3nuLwzo2c2LIlM2bM0IhzEZEIURGXfMs68jwtLY20tDSOP/54Pv64OiNXTmXsxOkkJibqLmMiIhGk/2GlwLZv384999xD48aNuf322wHo0qULK1euZNCgQSrgIiIRppa45NvhnZsYOXIkL774IgcOHKBXr16/uDWous5FRIqGirjkqcsD77P5x1SwMpgZGSve5IXP53HVVVdx00030bJly2hHFBEplVTEJVfbt29n9dyXqPZNEtOmTeOcc87hu+9OJy4uTncWExGJMhVx+dVoc/cjHEhZTurnc9n/1UI4kk77hIRj57jr1KkTragiIpKJirgcG22+d+9e4uPjOXjwIHXrDqeiGdfddCPXXHMNp512WrRjiohIFiripVDmlndG2l7KbVzIOefcx7Zt21i/fj3ly5dn/vz5nHbaaZQvXz7KaUVEJCcq4qXQlt1pvNgnngcffJB3332X9PR0KrRsyciRIzl06BDly5enffv20Y4pIiJ5UBEvgbKbUS0jbS9p6xdRvkErGjduwo8//sgXX3zB6NGjGTRoEB06dNClYSIiMUZFvAQ6eo77m2++4c033+T1118nOTmZjIwMHn74Yf7yl/PIyMigb9++KtwiIjFMRbwEONry9ozDZOzbRaOGjdi/fz+nnnoqhw4dokWLFtxyyy3069ePjh07AhAXFxfl1CIiUlgq4jHM3Vm3bh1r5r9C14pbSUpKonXr1nz85AIApk2bRtu2bWnWrFmUk4qISCSoiMcQdyclJYUmTZoAcNVVV/Hvf/8bgNWnnMLQoUPp3bv3sfX79+8flZwiIlI0VMSLsYMHD7J8+XI+/vhjPvroIz766CO2b9/Otm3bOPHEExkyZAjdunVj/GJj/dPXRDuuiIgUMRXxYiIjI4Mvv/ySJUuWkJCQQP369Zk2bRojRowA4OSTT6Z379506dKFcuXKARxrdd/39Zyo5RYRkehREY+irVu38sADD7B06VKWL1/Ovn37AHjuuecYMWIEF110EbNmzeKss86ibt26x7bLeglZveoVizy7iIhEn4p4BB05coQVK1awZs0aVq1axerVq1m1ahUjRozg1ltvpWzZskyePJn27dszYsQIOnbsSMeOHTn11FMBqFu3Lv369fvVfo9eQiYiIqWbingBZG4JHzl8gPTd3wceu76jVdxWVt07jaqd+uJHMtj4yADIOAxWhrI16lKuVkMeXrCbf40JdIHX/OPLbLYybAZmrwHWfAt8m+v7q+UtIiIQ4SJuZr2Ax4A44Fl3fyDL6+WBF4GOwE5gkLunRDJTfu3cuZNvv/2WTZs2sXnzZjZt2sTqBd+x638vANC0aVM2ff31sfWXVa7M0KFD+Vewpfx2j9dp0KABzZo10zzkIiISVhEr4mYWB0wELgA2A5+Z2Wx3X51ptd8Bu9y9qZn9FngQGBSpTNlp+4cn2LJhHRn7dnFk/24yUndBmThO6HsrAN+/fDsHN674eYMyZal2crtji+PHjycuLo6mTZtyyimnsGLFChISEo69nvmSLxERkXCKZEv8DGC9u28AMLPpQF8gcxHvC4wPfj8TeMLMzN09grl+YcMHr7FvVRIANWrUoF7t2jRv3pzXgy3puT3Ksn//fho0aECDBg044YQTjt1XG+DKK68sqqgiIiK/EMkiXg/YlGl5M3BmTuu4e7qZ7QFqAjsyr2Rm1wLXBhdTzWxdJALv2rWLXbt2sXbt2sLMKV6LLPmlUHQ8w0vHM/x0TMOrRBxPezCsu2uU0wuRLOLZVcGsLexQ1sHdJwGTwhEq0sxssbt3inaOkkLHM7x0PMNPxzS8dDzzp0zeqxTYZqBBpuX6wNac1jGzskA14McIZhIRESkxIlnEPwOamVkTMysH/BaYnWWd2cCw4PcDgPeL8ny4iIhILItYd3rwHPcoYC6BS8wmu/sqM7sbWOzus4HngJfMbD2BFvhvI5WnCMVEt38M0fEMLx3P8NMxDS8dz3wwNXxFRERiUyS700VERCSCVMRFRERilIp4BJjZ38xsrZmtMLP/mFn1aGeKZWaWaGarzOyImenSkwIys15mts7M1pvZmGjniXVmNtnMfjCzL6KdpSQwswZmlmRma4L/3v8U7UyxQEU8Mt4DWrt7W+BL4LYo54l1XwD9gA+iHSRWZZoGuTfQEhhsZi2jmyrmTQF6RTtECZIO/MXdTwPOAv6o39G8qYhHgLu/6+7pwcVPCVwjLwXk7mvcPSKz9JUix6ZBdvdDwNFpkKWA3P0DNK9F2Lj7d+6+NPj9XmANgVk9JRcq4pE3Ang72iGk1MtuGmT9BynFkpk1BjoAC6ObpPjT/cQLyMzmASdl89Id7v56cJ07CHQRTS3KbLEolOMphRLSFMci0WZmVYBZwE3u/lO08xR3KuIF5O7n5/a6mQ0DLgF6aha6vOV1PKXQQpkGWSSqzOw4AgV8qru/Fu08sUDd6RFgZr2AW4HL3H1/tPOIENo0yCJRY4FbRz4HrHH3R6KdJ1aoiEfGE0A88J6ZLTezp6IdKJaZ2W/MbDNwNjDHzOZGO1OsCQ60PDoN8hrgFXdfFd1Usc3MXgYWAC3MbLOZ/S7amWJcF2AocF7w/83lZtYn2qGKO027KiIiEqPUEhcREYlRKuIiIiIxSkVcREQkRqmIi4iIxCgVcRERkRilIi5SwgUv0Vue5XHEzHqHYd+p4cgoIgWjS8xEShkzuxa4Aujh7kcKua9Ud68SnmQikl9qiYuUImbWHLgTGJq1gJvZg2b2h0zL483sL2ZWxczmm9lSM1tpZr+6+5mZJZjZm5mWnzCz4cHvO5rZ/8xsiZnNNbM6EfuAIqWMirhIKRGcl3oa8Fd335jNKtOBQZmWBwKvAgeA37j76UAP4O/BKTJDfc/HgQHu3hGYDNxX8E8hIpnpBigipcc9wCp3n57di+6+zMxONLO6wAnALnffGCzEE8ysG3CEwC1MawPfh/CeLYDWBKYgBogDviv8RxERUBEXKRXMLAHoD5yex6ozgQEEbgt7tNhfQaCod3T3w2aWAlTIsl06v+zZO/q6EfjD4ewChxeRHKk7XaSEM7MawPPAVe6+N4/VpxO4w9kAAgUdoBrwQ7CA9wAaZbPdt0BLMytvZtWAnsHn1wEnmNnZwSzHmVmrwn0iETlKLXGRku864ETgX1lOZd/v7jMyP+Huq8wsHtji7ke7vacCb5jZYmA5sDbrG7j7JjN7BVgBfAUsCz5/yMwGAP8MFveywD8A3UFNJAx0iZmIiEiMUne6iIhIjFIRFxERiVEq4iIiIjFKRVxERCRGqYiLiIjEKBVxERGRGKUiLiIiEqP+HytFZdXBEh8DAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "needs_background": "light" + }, + "output_type": "display_data" + }, + { + "data": { + "text/plain": [ + "1.01" + ] + }, + "execution_count": 207, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "compute_sigma(generate_normal(100),x90=0.9,mu=0,std=1,n_bins=100)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Exam.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 +} From 8edae43116efe64191b44c12cb2df30017255f7a Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 17 Apr 2020 14:27:01 -0500 Subject: [PATCH 09/12] Md Arifur Rahman Lab-5-Submission Md Arifur Rahman mxr8032 --- Labs/Lab-5/Lab-5-Submission.ipynb | 1154 +++++++++++++++++++++++++++++ 1 file changed, 1154 insertions(+) create mode 100644 Labs/Lab-5/Lab-5-Submission.ipynb diff --git a/Labs/Lab-5/Lab-5-Submission.ipynb b/Labs/Lab-5/Lab-5-Submission.ipynb new file mode 100644 index 0000000..7c3e588 --- /dev/null +++ b/Labs/Lab-5/Lab-5-Submission.ipynb @@ -0,0 +1,1154 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "_AN5Pm3BDHKM" + }, + "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": { + "colab_type": "text", + "id": "SYVcvDI_DHKP" + }, + "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": 105, + "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=0" + ] + }, + { + "cell_type": "code", + "execution_count": 106, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 107, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Max value reached.\n" + ] + } + ], + "source": [ + "my_counter.increment()\n", + "my_counter.increment()\n", + "my_counter.increment()\n", + "my_counter.increment()" + ] + }, + { + "cell_type": "code", + "execution_count": 108, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter.cur_val=100" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "JyZT4vPfDHKR" + }, + "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": 109, + "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", + " def cur_val(self):\n", + " return self.__cur_val\n", + " def max_val(self):\n", + " return self.__max_val" + ] + }, + { + "cell_type": "code", + "execution_count": 110, + "metadata": {}, + "outputs": [], + "source": [ + "my_counter=counter(3)" + ] + }, + { + "cell_type": "code", + "execution_count": 111, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "1" + ] + }, + "execution_count": 111, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_counter.cur_val()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "0vN3ya9SDHKW" + }, + "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": 112, + "metadata": {}, + "outputs": [], + "source": [ + "class Rectangle:\n", + " def __init__(self,width,length,x,y):\n", + " self.__width=width\n", + " self.__length=length\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " def getArea(self):\n", + " return self.__width*self.__length\n", + " \n", + " def getPerimeter(self):\n", + " return 2*(self.__width+self.__length)\n", + " \n", + " def getWidth(self):\n", + " return self.__width\n", + " \n", + " def getLength(self):\n", + " return self.__length\n", + " \n", + " def getCorner(self):\n", + " return self.__x,self.__y\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 113, + "metadata": {}, + "outputs": [], + "source": [ + "myr=Rectangle(5,10,0,0)" + ] + }, + { + "cell_type": "code", + "execution_count": 114, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "50" + ] + }, + "execution_count": 114, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myr.getArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 115, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "30" + ] + }, + "execution_count": 115, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myr.getPerimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 116, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 0)" + ] + }, + "execution_count": 116, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "myr.getCorner()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "7vCMVTzIDHKY" + }, + "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 perimeter of the circle. Make all data members private and privide accessors to retrieve values of data members. " + ] + }, + { + "cell_type": "code", + "execution_count": 117, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "class Circle:\n", + " def __init__(self,radius,x,y):\n", + " self.__radius=radius\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " def getArea(self):\n", + " return self.__radius**2*math.pi\n", + " \n", + " def getPerimeter(self):\n", + " return self.__radius*2*math.pi\n", + " \n", + " def getRadius(self):\n", + " return self.__radius\n", + " \n", + " def getCenter(self):\n", + " return self.__x,self.__y\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 118, + "metadata": {}, + "outputs": [], + "source": [ + "my_circle=Circle(5,0,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 119, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "78.53981633974483" + ] + }, + "execution_count": 119, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_circle.getArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 120, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "31.41592653589793" + ] + }, + "execution_count": 120, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_circle.getPerimeter()" + ] + }, + { + "cell_type": "code", + "execution_count": 121, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "5" + ] + }, + "execution_count": 121, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_circle.getRadius()" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(0, 3)" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "my_circle.getCenter()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "eSnGmwONDHKZ" + }, + "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": 137, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "class Geometry:\n", + " def __init__(self,x,y):\n", + " self.x=x\n", + " self.y=y\n", + " \n", + " def getArea(self):\n", + " raise NotImplementedError\n", + " \n", + " def getPerimeter(self):\n", + " raise NotImplementedError\n", + " \n", + " def getWidth(self):\n", + " raise NotImplementedError\n", + " \n", + " def getLength(self):\n", + " raise NotImplementedError\n", + " \n", + " def getRadius(self):\n", + " raise NotImplementedError\n", + " \n", + " def getCord(self):\n", + " return self.x,self.y\n", + "\n", + "class Rectangle(Geometry):\n", + " def __init__(self,width,length,x,y):\n", + " self.__width=width\n", + " self.__length=length\n", + " #super(Geometry,self).__init__(x,y)\n", + " Geometry.__init__(self,x,y) \n", + " def getArea(self):\n", + " return self.__width*self.__length\n", + " \n", + " def getPerimeter(self):\n", + " return 2*(self.__width+self.__length)\n", + " \n", + " def getWidth(self):\n", + " return self.__width\n", + " \n", + " def getLength(self):\n", + " return self.__length\n", + " \n", + " def getCord(self):\n", + " return self.x,self.y\n", + "\n", + "class Circle(Geometry):\n", + " def __init__(self,radius,x,y):\n", + " self.__radius=radius\n", + " #super(Geometry,self).__init__(x,y)\n", + " Geometry.__init__(self,x,y) \n", + " def getArea(self):\n", + " return self.__radius**2*math.pi\n", + " \n", + " def getPerimeter(self):\n", + " return self.__radius*2*math.pi\n", + " \n", + " def getRadius(self):\n", + " return self.__radius\n", + " \n", + " def getCord(self):\n", + " return self.x,self.y\n" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [], + "source": [ + "ob = Rectangle(2,3,5,6)" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6" + ] + }, + "execution_count": 139, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ob.getArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(5, 6)" + ] + }, + "execution_count": 140, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ob.getCord()" + ] + }, + { + "cell_type": "code", + "execution_count": 141, + "metadata": {}, + "outputs": [], + "source": [ + "ob1 = Circle(2,5,5)" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.566370614359172" + ] + }, + "execution_count": 143, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ob1.getArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 142, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(5, 5)" + ] + }, + "execution_count": 142, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ob1.getCord()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "A_jUTYegDHKa" + }, + "source": [ + "6. Implement an analogous triangle class." + ] + }, + { + "cell_type": "code", + "execution_count": 123, + "metadata": {}, + "outputs": [], + "source": [ + "class AnalogousTriangle:\n", + " def __init__(self, x1, y1, x2, y2, x3, y3):\n", + " #Where (x1,y1); (x2,y2) and (x3,y3)are coordinates of vertices of the triangle\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", + " # Area = [ x1(y2 – y3) + x2(y3 – y1) + x3(y1-y2)]/2\n", + " def getArea(self):\n", + " return abs((self.__x1 * (self.__y2 - self.__y3) + \n", + " self.__x2 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y2)) / 2.0)\n", + " def getPerimeter(self):\n", + " AB = ((self.__x1-self.__x2)**2 +(self.__y1-self.__y2)**2)**0.5\n", + " BC = ((self.__x2-self.__x3)**2 +(self.__y2-self.__y3)**2)**0.5\n", + " CA = ((self.__x3-self.__x1)**2 +(self.__y3-self.__y1)**2)**0.5\n", + " return AB+BC+CA" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [], + "source": [ + "obtr = AnalogousTriangle(0,0,4,0,0,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 125, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "6.0" + ] + }, + "execution_count": 125, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "obtr.getArea()" + ] + }, + { + "cell_type": "code", + "execution_count": 126, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "12.0" + ] + }, + "execution_count": 126, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "obtr.getPerimeter()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ykAEQZiJDHKf" + }, + "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": 127, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "class Rectangle:\n", + " def __init__(self,x1, y1, x2, y2, x3, y3,x4, y4):# Cords of four corners\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.__x4=x4\n", + " self.__y4=y4\n", + " \n", + " def getArea(self): \n", + " return abs((self.__x1 * (self.__y2 - self.__y3) + \n", + " self.__x2 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y2)) / 2.0) + abs((self.__x1 * (self.__y4 - self.__y3) + \n", + " self.__x4 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y4)) / 2.0)\n", + " def getPerimeter(self):\n", + " AB = ((self.__x1-self.__x2)**2 +(self.__y1-self.__y2)**2)**0.5\n", + " BC = ((self.__x2-self.__x3)**2 +(self.__y2-self.__y3)**2)**0.5\n", + " CD = ((self.__x3-self.__x4)**2 +(self.__y3-self.__y4)**2)**0.5\n", + " DA = ((self.__x4-self.__x1)**2 +(self.__y4-self.__y1)**2)**0.5\n", + " return AB+BC+CD+DA\n", + "\n", + "# A function to check whether point P(x, y) lies inside the rectangle \n", + "# formed by A(x1, y1), B(x2, y2),C(x3, y3) and D(x4, y4) \n", + " def check(self, x, y):\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " # Calculate area of rectangle ABCD \n", + " A = abs((self.__x1 * (self.__y2 - self.__y3) + \n", + " self.__x2 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y2)) / 2.0)+ abs((self.__x1 * (self.__y4 - self.__y3) + \n", + " self.__x4 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y4)) / 2.0)\n", + " \n", + " # Calculate area of triangle PAB \n", + " A1 = abs((self.__x * (self.__y1 - self.__y2) + \n", + " self.__x1 * (self.__y2 - self.__y) + \n", + " self.__x2 * (self.__y - self.__y1)) / 2.0)\n", + " \n", + " # Calculate area of triangle PBC \n", + " A2 = abs((self.__x * (self.__y2 - self.__y3) + \n", + " self.__x2 * (self.__y3 - self.__y) + \n", + " self.__x3 * (self.__y - self.__y2)) / 2.0)\n", + " \n", + " # Calculate area of triangle PCD \n", + " A3 = abs((self.__x * (self.__y3 - self.__y4) + \n", + " self.__x3 * (self.__y4 - self.__y) + \n", + " self.__x4 * (self.__y - self.__y3)) / 2.0)\n", + " \n", + " # Calculate area of triangle PAD \n", + " A4 = abs((self.__x * (self.__y1 - self.__y4) + \n", + " self.__x1 * (self.__y4 - self.__y) + \n", + " self.__x4 * (self.__y - self.__y1)) / 2.0)\n", + " \n", + " # Check if sum of A1, A2, A3 \n", + " # and A4 is same as A \n", + " if A == A1 + A2 + A3 + A4:\n", + " print(\"Yes! Located inside the Rectangle\")\n", + " else:\n", + " print(\"Located outside of the Rectangle\") \n", + "\n", + " \n", + "class Circle:\n", + " def __init__(self,radius, x1,y1):\n", + " self.__radius=radius\n", + " self.__x1=x1\n", + " self.__y1=y1\n", + " \n", + " def getArea(self):\n", + " return self.__radius**2*math.pi\n", + " \n", + " def getPerimeter(self):\n", + " return self.__radius*2*math.pi\n", + " \n", + " def getRadius(self):\n", + " return self.__radius\n", + " \n", + " def getCenter(self):\n", + " return self.__x1,self.__y1\n", + "\n", + "# Compare radius of circle with distance of its center from given point (x,y) \n", + " def check(self, x, y):\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " if ((x - self.__x1) * (x - self.__x1) + \n", + " (y - self.__y1) * (y - self.__y1) <= self.__radius * self.__radius): \n", + " print(\"Yes! Located Inside the Circle\") \n", + " else: \n", + " print(\"Located Outside of the Circle\") \n", + " \n", + "\n", + " \n", + "class Triangle:\n", + " def __init__(self,x1, y1, x2, y2, x3, y3):\n", + " self.__x1=x1\n", + " self.__y1=y1\n", + " self.__x2=x2\n", + " self.__y2=y2\n", + " self.__x3=x3\n", + " self.__y3=y3\n", + " \n", + " def getArea(self): \n", + " return abs((self.__x1 * (self.__y2 - self.__y3) + self.__x2 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y2)) / 2.0)\n", + " def getPerimeter(self):\n", + " AB = ((self.__x1-self.__x2)**2 +(self.__y1-self.__y2)**2)**0.5\n", + " BC = ((self.__x2-self.__x3)**2 +(self.__y2-self.__y3)**2)**0.5\n", + " CA = ((self.__x3-self.__x1)**2 +(self.__y3-self.__y1)**2)**0.5\n", + " return AB+BC+CA\n", + " \n", + "# A function to check whether point P(x, y) \n", + "# lies inside the triangle formed by \n", + "# A(x1, y1), B(x2, y2) and C(x3, y3)\n", + " def check(self, x, y):\n", + " self.__x=x\n", + " self.__y=y\n", + " \n", + " # Calculate area of triangle ABC \n", + " \n", + " A = abs((self.__x1 * (self.__y2 - self.__y3) + self.__x2 * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y2)) / 2.0) \n", + "\n", + " # Calculate area of triangle PBC \n", + " A1 = A1= abs((self.__x * (self.__y2 - self.__y3) + self.__x2 * (self.__y3 - self.__y) + \n", + " self.__x3 * (self.__y - self.__y2)) / 2.0) \n", + " \n", + " # Calculate area of triangle PAC \n", + " A2= abs((self.__x1 * (self.__y - self.__y3) + self.__x * (self.__y3 - self.__y1) + \n", + " self.__x3 * (self.__y1 - self.__y)) / 2.0) \n", + " \n", + " # Calculate area of triangle PAB \n", + " A3 = abs((self.__x1 * (self.__y2 - self.__y) + self.__x2 * (self.__y - self.__y1) + \n", + " self.__x * (self.__y1 - self.__y2)) / 2.0)\n", + " \n", + " # Check if sum of A1, A2 and A3 is same as A \n", + " if A == A1 + A2 + A3:\n", + " print(\"Yes! Located Inside the Triangle\")\n", + " else:\n", + " print(\"No! Located Outside of the Triangle\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 128, + "metadata": {}, + "outputs": [], + "source": [ + "obr=Rectangle(0, 10, 10, 0, 0, -10, -10, 0)\n", + "obc = Circle(2,0,1)\n", + "obt = Triangle(0, 0, 20, 0, 10, 30)" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Area of Rectangle: 200.0\n", + "Area of Circle: 12.566370614359172\n", + "Area of Triangle: 300.0\n" + ] + } + ], + "source": [ + "print(\"Area of Rectangle:\",obr.getArea())\n", + "print(\"Area of Circle:\",obc.getArea())\n", + "print(\"Area of Triangle:\",obt.getArea())" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Perimeter of Rectangle: 56.568542494923804\n", + "Perimeter of Circle: 12.566370614359172\n", + "Perimeter of Triangle: 83.24555320336759\n" + ] + } + ], + "source": [ + "print(\"Perimeter of Rectangle:\",obr.getPerimeter())\n", + "print(\"Perimeter of Circle:\",obc.getPerimeter())\n", + "print(\"Perimeter of Triangle:\",obt.getPerimeter())" + ] + }, + { + "cell_type": "code", + "execution_count": 131, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yes! Located inside the Rectangle\n", + "Yes! Located Inside the Circle\n", + "Yes! Located Inside the Triangle\n" + ] + } + ], + "source": [ + "obr.check(0,0)\n", + "obc.check(1,1)\n", + "obt.check(10,15)" + ] + }, + { + "cell_type": "code", + "execution_count": 132, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Located outside of the Rectangle\n", + "Located Outside of the Circle\n", + "No! Located Outside of the Triangle\n" + ] + } + ], + "source": [ + "obr.check(20,20)\n", + "obc.check(5,1)\n", + "obt.check(10,35)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "l0AXvbm9DHKh" + }, + "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 perimeter of the object.\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 133, + "metadata": {}, + "outputs": [], + "source": [ + "class RectanglePoints:\n", + " #generate each pixel in a rectangle, given the min/max x/y coordinates of the given rectangle\n", + " def __init__(self, min_x, min_y, max_x, max_y):\n", + " self.__min_x=min_x\n", + " self.__min_y=min_y\n", + " self.__max_x=max_x\n", + " self.__max_y=max_y\n", + " \n", + " def Coordinates(self):\n", + " x, y = self.__min_x, self.__min_y\n", + " points= []\n", + " for dx, dy in (1, 0), (0, 1), (-1, 0), (0, -1):\n", + " while x in range(self.__min_x, self.__max_x+1) and y in range(self.__min_y, self.__max_y+1):\n", + " points.append((x, y))\n", + " x += dx\n", + " y += dy\n", + " x -= dx\n", + " y -= dy\n", + " return points\n", + "\n", + "import math\n", + "class CirclePoints:\n", + " def __init__(self, x, y, radius):\n", + " self.__x=x\n", + " self.__y=y\n", + " self.__radius=radius\n", + " def rotate(self):\n", + " # returns coordinates in a tuple (x,y)\n", + " rx = (self.__x*math.cos(self.__r)) - (self.__y*math.sin(self.__r))\n", + " ry = (self.__y*math.cos(self.__r)) + (self.__x*math.sin(self.__r))\n", + " return (rx, ry)\n", + "# create a ring of points centered on center (x,y) with a given radius\n", + "# center should be a tuple or list of coordinates (x,y)\n", + "# returns a list of point coordinates in tuples\n", + " def Coordinates(self, num_points):\n", + " self.__num_points=num_points\n", + " arc = (2 * math.pi) / self.__num_points #angle between two of the points\n", + " points = []\n", + " for p in range(self.__num_points):\n", + " (px,py) = rotate(0, self.__radius, arc * p) \n", + " px += self.__x\n", + " py += self.__y\n", + " points.append((px,py))\n", + " return points\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 134, + "metadata": {}, + "outputs": [], + "source": [ + "objr = RectanglePoints(0,0,10,10)\n", + "objc=CirclePoints(1,1,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 135, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Points on the Rectangle are: [(0, 0), (1, 0), (2, 0), (3, 0), (4, 0), (5, 0), (6, 0), (7, 0), (8, 0), (9, 0), (10, 0), (10, 0), (10, 1), (10, 2), (10, 3), (10, 4), (10, 5), (10, 6), (10, 7), (10, 8), (10, 9), (10, 10), (10, 10), (9, 10), (8, 10), (7, 10), (6, 10), (5, 10), (4, 10), (3, 10), (2, 10), (1, 10), (0, 10), (0, 10), (0, 9), (0, 8), (0, 7), (0, 6), (0, 5), (0, 4), (0, 3), (0, 2), (0, 1), (0, 0)]\n", + "Points on the Circle are: [(1.0, 4.0), (-0.1480502970952693, 3.77163859753386), (-1.1213203435596428, 3.121320343559643), (-1.77163859753386, 2.1480502970952697), (-2.0, 1.0000000000000002), (-1.77163859753386, -0.1480502970952693), (-1.1213203435596428, -1.1213203435596424), (-0.14805029709526973, -1.77163859753386), (0.9999999999999997, -2.0), (2.148050297095269, -1.7716385975338604), (3.1213203435596424, -1.1213203435596428), (3.7716385975338595, -0.14805029709527107), (4.0, 0.9999999999999994), (3.77163859753386, 2.1480502970952697), (3.121320343559643, 3.121320343559642), (2.148050297095271, 3.7716385975338595)]\n" + ] + } + ], + "source": [ + "print(\"Points on the Rectangle are:\",objr.Coordinates())\n", + "print(\"Points on the Circle are:\",objc.Coordinates(16))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "rCcX3viBDHKh" + }, + "source": [ + "9. Add a function in the base class of the object classes that returns true/false testing that the object overlaps with another object." + ] + }, + { + "cell_type": "code", + "execution_count": 136, + "metadata": {}, + "outputs": [], + "source": [ + "class OverlapRectangle:\n", + " def __init__(self, l1x,l1y, r1x,r1y, l2x,l2y, r2x,r2y):\n", + " self.__l1x=l1x\n", + " self.__l1y=l1y\n", + " self.__r1x=r1x\n", + " self.__r1y=r1y\n", + " self.__l2x=l2x\n", + " self.__l2y=l2y\n", + " self.__r2x=r2x\n", + " self.__r2y=r2y\n", + " \n", + "#a rectangle can be represented by two coordinates, top left and bottom right.\n", + "#l1: Top Left coordinate of first rectangle.\n", + "#r1: Bottom Right coordinate of first rectangle.\n", + "#l2: Top Left coordinate of second rectangle.\n", + "#r2: Bottom Right coordinate of second rectangle.\n", + " \n", + " # Returns true if two rectangles(l1, r1) and (l2, r2) overlap \n", + " def checkOverlap(self):\n", + " # If one rectangle is on left side of other \n", + " if (self.__l1x> self.__r2x or self.__l2x>self.__r1x):\n", + " return False\n", + " # If one rectangle is above other \n", + " if (self.__l1y < self.__r2y or self.__l2y < self.__r1y):\n", + " return False\n", + " return True\n", + " \n", + "class OverlapCircle:\n", + " def __init__(self,x1, y1, x2, y2, r1, r2):\n", + " self.__x1=x1\n", + " self.__y1=y1\n", + " self.__x2=x2\n", + " self.__y2=y2\n", + " self.__r1=r1\n", + " self.__r2=r2\n", + "#Distance between centers C1 and C2 is calculated as C1C2 = sqrt((x1 - x2)2 + (y1 - y2)2).\n", + "#There are three condition arises.\n", + "#1. If C1C2 == R1 + R2 ;Circle A and B are touch to each other.\n", + "#2. If C1C2 > R1 + R2 ;Circle A and B are not touch to each other.\n", + "#3. If C1C2 < R1 + R2 ;Circle intersects each other.\n", + " \n", + " def checkOverlap(self):\n", + " distSqured = (self.__x1-self.__x2)*(self.__x1-self.__x2)+(self.__y1-self.__y2)*(self.__y1-self.__y2) \n", + " radSumSqured = (self.__r1 + self.__r2) * (self.__r1 + self.__r2) \n", + " if (distSqured == radSumSqured): \n", + " return True \n", + " elif (distSqured > radSumSqured): \n", + " return False\n", + " else: \n", + " return True " + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [], + "source": [ + "objr = OverlapRectangle(0,10, 10,0, 5,5, 15,0)\n", + "objc = OverlapCircle(-10,8, 14,-24, 30,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 138, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n" + ] + } + ], + "source": [ + "print(objr.checkOverlap())\n", + "print(objc.checkOverlap())" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [], + "source": [ + "objr1 = OverlapRectangle(10,10, 0,0, 5,5, 15,0)\n", + "objc1 = OverlapCircle(-10,8, 14,-24, 10,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 140, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n" + ] + } + ], + "source": [ + "print(objr1.checkOverlap())\n", + "print(objr1.checkOverlap())" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Lab-5.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 +} From 593ed9eea4ce805e9ec865e64d4c43108ec9ff57 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 24 Apr 2020 14:44:00 -0500 Subject: [PATCH 10/12] Lab-6 Submission Md Arifur Rahman --- Labs/Lab-6/Lab-6-Submission.ipynb | 2021 +++++++++++++++++++++++++++++ 1 file changed, 2021 insertions(+) create mode 100644 Labs/Lab-6/Lab-6-Submission.ipynb diff --git a/Labs/Lab-6/Lab-6-Submission.ipynb b/Labs/Lab-6/Lab-6-Submission.ipynb new file mode 100644 index 0000000..d1e1c85 --- /dev/null +++ b/Labs/Lab-6/Lab-6-Submission.ipynb @@ -0,0 +1,2021 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Lab 6\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Matrix Representation: In this lab you will be creating a simple linear algebra system. In memory, we will represent matrices as nested python lists as we have done in lecture. \n", + "\n", + "1. Create a `matrix` class with the following properties:\n", + " * It can be initialized in 2 ways:\n", + " 1. with arguments `n` and `m`, the size of the matrix. A newly instanciated matrix will contain all zeros.\n", + " 2. with a list of lists of values. Note that since we are using lists of lists to implement matrices, it is possible that not all rows have the same number of columns. Test explicitly that the matrix is properly specified.\n", + " * Matrix instances `M` can be indexed with `M[i][j]` and `M[i,j]`.\n", + " * Matrix assignment works in 2 ways:\n", + " 1. If `M_1` and `M_2` are `matrix` instances `M_1=M_2` sets the values of `M_1` to those of `M_2`, if they are the same size. Error otherwise.\n", + " 2. In example above `M_2` can be a list of lists of correct size.\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "#A\n", + "class MatrixA:\n", + " def __init__(self):\n", + " pass\n", + " def zeroMatrix(self,n,m):\n", + " self.n = n\n", + " self.m = m\n", + " return [[0]*self.m for i in range(self.n)]\n", + " def addValues(self):\n", + " M=self.zeroMatrix(self.n,self.m)\n", + " for i in range(self.n):\n", + " for j in range(self.m):\n", + " M[i][j]=int(input())\n", + " return M\n", + " \n", + " def shapeMatrix(self,M):\n", + " self.M = M\n", + " if isinstance(self.M,list):\n", + " row_length=len(self.M[0])\n", + " n=len(self.M)\n", + " m=len(self.M[0])\n", + " for row in self.M:\n", + " if not row_length==len(row):\n", + " return False\n", + " else:\n", + " False\n", + " return n,m\n", + " def setValues(self,M1,M2):\n", + " self.M1 = M1\n", + " self.M2 = M2\n", + " if self.shapeMatrix(self.M1)==self.shapeMatrix(self.M2):\n", + " for i in range(len(self.M1)):\n", + " for j in range(len(self.M1[0])):\n", + " self.M2[i][j]=self.M1[i][j]\n", + " return self.M2\n", + " else:\n", + " print(\"The matrix are not of same shape!\")\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "M1 = MatrixA()\n", + "M2 = MatrixA()" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0], [0, 0, 0]]" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M1.zeroMatrix(2,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0, 0, 0], [0, 0, 0]]" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M2.zeroMatrix(2,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n" + ] + }, + { + "data": { + "text/plain": [ + "[[1, 2, 3], [4, 5, 6]]" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M3=M1.addValues()\n", + "M3" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9\n", + "8\n", + "7\n", + "6\n", + "5\n", + "4\n" + ] + }, + { + "data": { + "text/plain": [ + "[[9, 8, 7], [6, 5, 4]]" + ] + }, + "execution_count": 6, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M4=M2.addValues()\n", + "M4" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Size of first Matrix is (2, 3)\n", + "Size of second Matrix is (2, 3)\n" + ] + } + ], + "source": [ + "print(\"Size of first Matrix is\", M1.shapeMatrix(M3))\n", + "print(\"Size of second Matrix is\",M2.shapeMatrix(M4))" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2, 3], [4, 5, 6]]" + ] + }, + "execution_count": 8, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#replacing values of second matrix by first matrix\n", + "M1.setValues(M3,M4)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "2. Add the following methods:\n", + " * `shape()`: returns a tuple `(n,m)` of the shape of the matrix.\n", + " * `transpose()`: returns a new matrix instance which is the transpose of the matrix.\n", + " * `row(n)` and `column(n)`: that return the nth row or column of the matrix M as a new appropriately shaped matrix object.\n", + " * `to_list()`: which returns the matrix as a list of lists.\n", + " * `block(n_0,n_1,m_0,m_1)` that returns a smaller matrix located at the n_0 to n_1 columns and m_0 to m_1 rows. \n", + " * (Extra credit) Modify `__getitem__` implemented above to support slicing.\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class Mattrix_methods(MatrixA):\n", + " def __init__(self):\n", + " super().__init__()\n", + " pass\n", + " def shape(self,M):\n", + " self.M = M\n", + " if isinstance(self.M,list):\n", + " length_row=len(self.M[0])\n", + " n=len(self.M)\n", + " m=len(self.M[0])\n", + " for row in self.M:\n", + " if not length_row==len(row):\n", + " return False\n", + " else:\n", + " False\n", + " return n,m\n", + " \n", + " def transpose(self,M):\n", + " self.M = M\n", + " n,m=self.shape(self.M)\n", + " MT=MatrixA.zeroMatrix(self,self.m,self.n)\n", + " for i in range(n):\n", + " for j in range(m):\n", + " MT[j][i]=M[i][j]\n", + " return MT\n", + " def row(self,M,n):\n", + " self.M = M\n", + " self.n = n\n", + " p,q=self.shape(self.M)\n", + " if len(self.M)>=self.n:\n", + " return self.M[self.n]\n", + " else:\n", + " print(\"Inser the value within the range of row\")\n", + " \n", + " def column(self,M,n):\n", + " self.M = M\n", + " self.n = n\n", + " p,q=self.shape(self.M)\n", + " self.column = list()\n", + " for i in range(p):\n", + " col = self.M[i][n]\n", + " self.column.append(col)\n", + " \n", + " return self.column\n", + " \n", + " def to_list(self,M):\n", + " self.M = M\n", + " self.Mat = []\n", + " p,q=self.shape(self.M)\n", + " for i in range(p):\n", + " self.row = []\n", + " for j in range(q):\n", + " self.row.append(self.M[i][j])\n", + " self.Mat.append(self.row)\n", + " return self.Mat\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", + " if self.n_0<0 or self.n_0>n or self.n_1n:\n", + " print(\"Column Number is not Valid!\")\n", + " elif self.m_0<0 or self.m_0>m or self.m_1m:\n", + " print(\"Row number is not Valid\")\n", + " else:\n", + " block_mat = []\n", + " for i in range(self.n_0-1,self.n_1):\n", + " row = []\n", + " for j in range(self.m_0-1,self.m_1):\n", + " row.append(M[i][j])\n", + " block_mat.append(row)\n", + " return block_mat\n", + " \n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [], + "source": [ + "mat = Mattrix_methods()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "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": 11, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m1 = mat.zeroMatrix(5,5)\n", + "m1" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "(5, 5)" + ] + }, + "execution_count": 12, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.shapeMatrix(m1)" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11\n", + "22\n", + "33\n", + "44\n", + "55\n", + "66\n", + "77\n", + "88\n", + "99\n", + "10\n", + "20\n", + "30\n", + "40\n", + "50\n", + "60\n", + "70\n", + "80\n", + "90\n", + "21\n", + "31\n", + "41\n", + "51\n", + "61\n", + "71\n", + "81\n" + ] + }, + { + "data": { + "text/plain": [ + "[[11, 22, 33, 44, 55],\n", + " [66, 77, 88, 99, 10],\n", + " [20, 30, 40, 50, 60],\n", + " [70, 80, 90, 21, 31],\n", + " [41, 51, 61, 71, 81]]" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m2 = mat.addValues()\n", + "m2" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[11, 66, 20, 70, 41],\n", + " [22, 77, 30, 80, 51],\n", + " [33, 88, 40, 90, 61],\n", + " [44, 99, 50, 21, 71],\n", + " [55, 10, 60, 31, 81]]" + ] + }, + "execution_count": 14, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m3 = mat.transpose(m2)\n", + "m3" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[44, 99, 50, 21, 71]" + ] + }, + "execution_count": 15, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.row(m3,3)" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[20, 30, 40, 50, 60]" + ] + }, + "execution_count": 16, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.column(m3,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[11, 66, 20, 70, 41],\n", + " [22, 77, 30, 80, 51],\n", + " [33, 88, 40, 90, 61],\n", + " [44, 99, 50, 21, 71],\n", + " [55, 10, 60, 31, 81]]" + ] + }, + "execution_count": 17, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "matlist = mat.to_list(m3)\n", + "matlist" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[40, 90], [50, 21]]" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "mat.block(m3,3,4,3,4)" + ] + }, + { + "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": 4, + "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", + " \n", + "def ones(n,m):\n", + " return [[1.]*m for i in range(n)]\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", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[10.0, 10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0, 10.0]]" + ] + }, + "execution_count": 20, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "constant(5,6,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[0.0, 0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 0.0, 0.0]]" + ] + }, + "execution_count": 21, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "zeros(5,6)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0, 1.0],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0, 1.0]]" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ones(5,6)" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 0.0, 0.0, 0.0, 0.0],\n", + " [0.0, 1.0, 0.0, 0.0, 0.0],\n", + " [0.0, 0.0, 1.0, 0.0, 0.0],\n", + " [0.0, 0.0, 0.0, 1.0, 0.0],\n", + " [0.0, 0.0, 0.0, 0.0, 1.0]]" + ] + }, + "execution_count": 23, + "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": 260, + "metadata": {}, + "outputs": [], + "source": [ + "class matrix_operation(Mattrix_methods):\n", + " def __init__(self):\n", + " super().__init__()\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", + " SM = zeros(n,m)\n", + " for i in range(n):\n", + " for j in range(m):\n", + " if isinstance(self.M,(list)):\n", + " SM[i][j]=M[i][j]*self.c\n", + " elif isinstance(self.c,(int,float)):\n", + " SM[i][j]=self.c*M[i][j]\n", + " return SM\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", + " MN = zeros(n1,m1)\n", + " #if self.shape(self.M)==self.shape(self.N):\n", + " if (n1,m1) ==(n2,m2): \n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " MN[i][j] = M[i][j]+N[i][j]\n", + " return MN\n", + " else:\n", + " print(\"The matrix are not of same shape\")\n", + " \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", + " MN1 = self.zeroMatrix(n1,m1)\n", + " if (n1,m1) ==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " MN1[i][j] = M[i][j]-N[i][j]\n", + " return MN1\n", + " else:\n", + " print(\"The matrix are not of same shape\")\n", + " \n", + " def mat_mult(self,M,N):\n", + " self.M = M\n", + " self.N = N\n", + " m1,n1=self.shape(self.M)\n", + " m2,n2=self.shape(self.N)\n", + " out_matrix= self.zeroMatrix(m1,n2)\n", + " if n1==m2:\n", + " for i in range(m1):\n", + " for j in range(n2):\n", + " for k in range(n1):\n", + " out_matrix[i][j]+=M[i][k]*N[k][j]\n", + " return out_matrix\n", + " else:\n", + " print(\"Matries are not of same shape, so multiplication is not possible!\")\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", + " MN2 = self.zeroMatrix(n1,m1)\n", + " if (n1,m1) ==(n2,m2):\n", + " for i in range(n1):\n", + " for j in range(m1):\n", + " MN2[i][j] = M[i][j]*N[i][j]\n", + " return MN2\n", + " else:\n", + " print(\"Matries are not of same shape, so multiplication is not possible!\")\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(\"Since the matrix are not of same shape, so they are not equal!\")\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [], + "source": [ + "op = matrix_operation()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "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],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0]]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m= constant(5,5,1)\n", + "m" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0]]" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "n= constant(5,5,4)\n", + "n" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "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],\n", + " [5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 28, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "p= constant(6,4,5)\n", + "p" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0]]" + ] + }, + "execution_count": 29, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.scalarmul(m,2)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.add(m,n)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The matrix are not of same shape\n" + ] + } + ], + "source": [ + "op.add(m,p)" + ] + }, + { + "cell_type": "code", + "execution_count": 32, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[-3.0, -3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0, -3.0],\n", + " [-3.0, -3.0, -3.0, -3.0, -3.0]]" + ] + }, + "execution_count": 32, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.sub(m,n)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The matrix are not of same shape\n" + ] + } + ], + "source": [ + "op.sub(m,p)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[20.0, 20.0, 20.0, 20.0, 20.0],\n", + " [20.0, 20.0, 20.0, 20.0, 20.0],\n", + " [20.0, 20.0, 20.0, 20.0, 20.0],\n", + " [20.0, 20.0, 20.0, 20.0, 20.0],\n", + " [20.0, 20.0, 20.0, 20.0, 20.0]]" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.mat_mult(m,n)" + ] + }, + { + "cell_type": "code", + "execution_count": 35, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Matries are not of same shape, so multiplication is not possible!\n" + ] + } + ], + "source": [ + "op.mat_mult(m,p)" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0],\n", + " [4.0, 4.0, 4.0, 4.0, 4.0]]" + ] + }, + "execution_count": 36, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.element_mult(m,n)" + ] + }, + { + "cell_type": "code", + "execution_count": 37, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Matries are not of same shape, so multiplication is not possible!\n" + ] + } + ], + "source": [ + "op.element_mult(m,p)" + ] + }, + { + "cell_type": "code", + "execution_count": 38, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 38, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m13 = constant(5,5,5)\n", + "m13" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0],\n", + " [5.0, 5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 39, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m14= constant(5,5,5)\n", + "m14" + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 40, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.equals(m13,m14)" + ] + }, + { + "cell_type": "code", + "execution_count": 41, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0]]" + ] + }, + "execution_count": 41, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m15 = constant(5,5,10)\n", + "m15" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 42, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "op.equals(m13,m15)" + ] + }, + { + "cell_type": "code", + "execution_count": 43, + "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],\n", + " [5.0, 5.0, 5.0, 5.0]]" + ] + }, + "execution_count": 43, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "m16 = constant(5,4,5)\n", + "m16" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Since the matrix are not of same shape, so they are not equal!\n" + ] + } + ], + "source": [ + "op.equals(m13,m16)" + ] + }, + { + "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": 405, + "metadata": {}, + "outputs": [], + "source": [ + "class operator_overloading(matrix_operation):\n", + " def __init__(self, M):\n", + " self.M = M\n", + " super().__init__()\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 __iadd__(self,other):\n", + " return self.setValues(self.M,other.M)" + ] + }, + { + "cell_type": "code", + "execution_count": 406, + "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],\n", + " [1.0, 1.0, 1.0, 1.0, 1.0]]" + ] + }, + "execution_count": 406, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x1=constant(5,5,1)\n", + "x1" + ] + }, + { + "cell_type": "code", + "execution_count": 407, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0]]" + ] + }, + "execution_count": 407, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "x2=constant(5,5,2)\n", + "x2" + ] + }, + { + "cell_type": "code", + "execution_count": 408, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 409, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0],\n", + " [2.0, 2.0, 2.0, 2.0, 2.0]]" + ] + }, + "execution_count": 409, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Testing\n", + "M*2" + ] + }, + { + "cell_type": "code", + "execution_count": 325, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 326, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[3.0, 3.0, 3.0, 3.0, 3.0],\n", + " [3.0, 3.0, 3.0, 3.0, 3.0],\n", + " [3.0, 3.0, 3.0, 3.0, 3.0],\n", + " [3.0, 3.0, 3.0, 3.0, 3.0],\n", + " [3.0, 3.0, 3.0, 3.0, 3.0]]" + ] + }, + "execution_count": 326, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Testing\n", + "M+N" + ] + }, + { + "cell_type": "code", + "execution_count": 327, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 328, + "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],\n", + " [-1.0, -1.0, -1.0, -1.0, -1.0]]" + ] + }, + "execution_count": 328, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Testing\n", + "M-N" + ] + }, + { + "cell_type": "code", + "execution_count": 329, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 330, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0],\n", + " [10.0, 10.0, 10.0, 10.0, 10.0]]" + ] + }, + "execution_count": 330, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Testing\n", + "M*N" + ] + }, + { + "cell_type": "code", + "execution_count": 332, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 333, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 333, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#Testing\n", + "M==N" + ] + }, + { + "cell_type": "code", + "execution_count": 334, + "metadata": {}, + "outputs": [], + "source": [ + "M=operator_overloading(x1)\n", + "N=operator_overloading(x2)" + ] + }, + { + "cell_type": "code", + "execution_count": 335, + "metadata": {}, + "outputs": [], + "source": [ + "#Testing\n", + "M=N" + ] + }, + { + "cell_type": "code", + "execution_count": 336, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 336, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "M==N" + ] + }, + { + "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": 444, + "metadata": {}, + "outputs": [], + "source": [ + "# Creatig a matrix object named as \"mat\"\n", + "mat = matrix_operation()" + ] + }, + { + "cell_type": "code", + "execution_count": 445, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n" + ] + }, + { + "data": { + "text/plain": [ + "[[1, 2], [3, 4]]" + ] + }, + "execution_count": 445, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A = mat.zeroMatrix(2,2)\n", + "A = mat.addValues()\n", + "A" + ] + }, + { + "cell_type": "code", + "execution_count": 446, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "9\n", + "8\n", + "7\n", + "6\n" + ] + }, + { + "data": { + "text/plain": [ + "[[9, 8], [7, 6]]" + ] + }, + "execution_count": 446, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "B = mat.zeroMatrix(2,2)\n", + "B = mat.addValues()\n", + "B" + ] + }, + { + "cell_type": "code", + "execution_count": 447, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2\n", + "2\n", + "2\n", + "2\n" + ] + }, + { + "data": { + "text/plain": [ + "[[2, 2], [2, 2]]" + ] + }, + "execution_count": 447, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "C = mat.zeroMatrix(2,2)\n", + "C = mat.addValues()\n", + "C" + ] + }, + { + "cell_type": "code", + "execution_count": 448, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[23, 20], [55, 48]]" + ] + }, + "execution_count": 448, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 6.1.(𝐴𝐵)𝐶=𝐴(𝐵𝐶)\n", + "AB = mat.mat_mult(A,B)\n", + "AB" + ] + }, + { + "cell_type": "code", + "execution_count": 449, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[86, 86], [206, 206]]" + ] + }, + "execution_count": 449, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ABCL = mat.mat_mult(AB,C)\n", + "ABCL" + ] + }, + { + "cell_type": "code", + "execution_count": 450, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[34, 34], [26, 26]]" + ] + }, + "execution_count": 450, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "BC = mat.mat_mult(B,C)\n", + "BC" + ] + }, + { + "cell_type": "code", + "execution_count": 451, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[86, 86], [206, 206]]" + ] + }, + "execution_count": 451, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ABCR = mat.mat_mult(A,BC)\n", + "ABCR" + ] + }, + { + "cell_type": "code", + "execution_count": 452, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 452, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "#(𝐴𝐵)𝐶=𝐴(𝐵𝐶) (Proved)\n", + "mat.equals(ABCL,ABCR)" + ] + }, + { + "cell_type": "code", + "execution_count": 453, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[11, 10], [9, 8]]" + ] + }, + "execution_count": 453, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 6.2. 𝐴(𝐵+𝐶)=𝐴𝐵+𝐴𝐶\n", + "B_plus_C = mat.add(B,C)\n", + "B_plus_C" + ] + }, + { + "cell_type": "code", + "execution_count": 454, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[29, 26], [69, 62]]" + ] + }, + "execution_count": 454, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AB_plus_C = mat.mat_mult(A,B_plus_C)\n", + "AB_plus_C" + ] + }, + { + "cell_type": "code", + "execution_count": 455, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[6, 6], [14, 14]]" + ] + }, + "execution_count": 455, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AC = mat.mat_mult(A,C)\n", + "AC" + ] + }, + { + "cell_type": "code", + "execution_count": 456, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[29, 26], [69, 62]]" + ] + }, + "execution_count": 456, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AB_plus_AC = mat.add(AB,AC)\n", + "AB_plus_AC" + ] + }, + { + "cell_type": "code", + "execution_count": 457, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 457, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 𝐴(𝐵+𝐶)=𝐴𝐵+𝐴𝐶 (Proved)\n", + "mat.equals(AB_plus_C,AB_plus_AC)" + ] + }, + { + "cell_type": "code", + "execution_count": 458, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[33, 50], [25, 38]]" + ] + }, + "execution_count": 458, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 6.3. 𝐴𝐵≠𝐵𝐴\n", + "BA = mat.mat_mult(B,A)\n", + "BA" + ] + }, + { + "cell_type": "code", + "execution_count": 459, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "False" + ] + }, + "execution_count": 459, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 𝐴𝐵≠𝐵𝐴 (Proved)\n", + "mat.equals(AB,BA)" + ] + }, + { + "cell_type": "code", + "execution_count": 460, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 0.0], [0.0, 1.0]]" + ] + }, + "execution_count": 460, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 6.4. 𝐴𝐼=𝐴\n", + "I = eye(2)\n", + "I" + ] + }, + { + "cell_type": "code", + "execution_count": 461, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1.0, 2.0], [3.0, 4.0]]" + ] + }, + "execution_count": 461, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "AI = mat.mat_mult(A,I)\n", + "AI" + ] + }, + { + "cell_type": "code", + "execution_count": 462, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[[1, 2], [3, 4]]" + ] + }, + "execution_count": 462, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "A" + ] + }, + { + "cell_type": "code", + "execution_count": 463, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 463, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# 𝐴𝐼=𝐴 (Proved)\n", + "mat.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 +} From 621953a50fb8c653fdfc41983704918f7598ee47 Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Fri, 8 May 2020 14:58:07 -0500 Subject: [PATCH 11/12] Submission lab 7 Submission --- Labs/Lab-7/Lab-7-Submission.ipynb | 7555 +++++++++++++++++++++++++++++ 1 file changed, 7555 insertions(+) create mode 100644 Labs/Lab-7/Lab-7-Submission.ipynb diff --git a/Labs/Lab-7/Lab-7-Submission.ipynb b/Labs/Lab-7/Lab-7-Submission.ipynb new file mode 100644 index 0000000..21f69cf --- /dev/null +++ b/Labs/Lab-7/Lab-7-Submission.ipynb @@ -0,0 +1,7555 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "VZ6Uy3j5RgWL" + }, + "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": 1031, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "lBmQMsX5RgWN" + }, + "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", + " super().__init__(name)\n", + " \n", + "class alg(base):\n", + " def __init__(self,name):\n", + " #base.__init__(self,name)\n", + " super().__init__(name)" + ] + }, + { + "cell_type": "code", + "execution_count": 1032, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "7Pz1VtfKRgWZ" + }, + "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", + " super().__init__(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", + " super().__init__(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": 1033, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "D5AjTZI9RgWs" + }, + "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)\n", + " super().__init__(name+\" Course Grade Book\")\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\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 1034, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "100\n" + ] + } + ], + "source": [ + "a_grade_book=grade_book(\"Test\")\n", + "a_grade_book[\"Example_Data\"]=100\n", + "print(a_grade_book[\"Example_Data\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 1035, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Test Course Grade Book'" + ] + }, + "execution_count": 1035, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "a_grade_book.name()" + ] + }, + { + "cell_type": "code", + "execution_count": 1036, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "sYMByu46RgWi" + }, + "outputs": [], + "source": [ + "class calculator(alg): \n", + " def __init__(self,name):\n", + " #alg.__init__(self,name)\n", + " super().__init__(name)\n", + "\n", + " def apply(self,a_grade_book):\n", + " raise NotImplementedError\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1037, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ob5V0z-ZRgW3" + }, + "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,\"D+\"),\n", + " (.63,\"D\"),\n", + " (.6,\"D-\"),\n", + " (.57,\"F+\"),\n", + " (.53,\"F\"),\n", + " (0.,\"F-\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,grade_name,max_grade=100.):\n", + " self.__max_grade=max_grade\n", + " self.__grade_name=grade_name\n", + " #calculator.__init__(self,\"Uncurved Percent Based Grade Calculator \"+self.__grade_name+\" Max=\"+str(self.__max_grade))\n", + " super().__init__(\"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": 1038, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "MBgfExZPRgW_" + }, + "outputs": [], + "source": [ + "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" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "collapsed": true, + "id": "DPOZ0PvrRgXF" + }, + "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": 1039, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "3W6yLofnRgXH" + }, + "outputs": [ + { + "name": "stderr", + "output_type": "stream", + "text": [ + "'cat' is not recognized as an internal or external command,\n", + "operable program or batch file.\n" + ] + } + ], + "source": [ + "!cat Data1401-Grades.csv " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "2GMXXwqBRgXN" + }, + "source": [ + "You will note that the first line has the names of the \"columns\" of data, and that subsequent lines (or \"rows\") have the data for each student, separated by cammas.\n", + "\n", + "Recalling that in lecture we created a file reader, create a CSV reader function that takes a filename as input and returns data structure(s) that store the data in the file. Note that you are not allowed to use a library. The point here is for *you* to write the CSV reader. Some options for your data structures (pick one):\n", + "\n", + "* A list of dictionaries, where each element of the list is corresponds to a row of data and the dictionaries are keyed by the column name. For example `data[5][\"l3_5\"]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* A list of lists (i.e. a 2-D array or matrix) and a dictionary, where each element of the \"matrix\" corresponds to a a specific grade for a specific student and the dictionary maps the name of the column to the column index. For example `data[5][column_names[\"l1_5\"]]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* A dictionary of lists, where each element of the dictionary corresponds to a column of data and the lists contain the data in that column. For example `data[\"l3_5\"][5]` corresponds to the 6th student's grade on lab 3 question 5.\n", + "\n", + "* (Extra Credit) A class that simultaneously supports all of the above methods." + ] + }, + { + "cell_type": "code", + "execution_count": 1040, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "jQ4FDkqiRgXN" + }, + "outputs": [], + "source": [ + "# Your solution here.\n", + "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", + " 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", + " data.append(row)\n", + " line = f.readline().rstrip()\n", + " f.close()\n", + " \n", + " read=list()\n", + " for i in range(len(data)):\n", + " read.append(dict(zip(fields,data[i])))\n", + " return read" + ] + }, + { + "cell_type": "code", + "execution_count": 1041, + "metadata": {}, + "outputs": [], + "source": [ + "data = csv_reader(\"Data1401-Grades.csv\")" + ] + }, + { + "cell_type": "code", + "execution_count": 1042, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.0\n" + ] + } + ], + "source": [ + "print(data[5][\"l3_5\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 1043, + "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(data):\n", + " print(i,v[\"l3_5\"])" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "UHLvFuBNRgXT" + }, + "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": 1044, + "metadata": {}, + "outputs": [], + "source": [ + "class_data=csv_reader(\"Data1401-Grades.csv\")\n", + "a_grade_book=grade_book(\"Data 1410\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + " #print(student_i,a_student_0.name())\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", + " #print(v)\n", + "\n", + " a_grade_book.add_student(a_student_0)" + ] + }, + { + "cell_type": "code", + "execution_count": 1045, + "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": 1046, + "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": { + "colab_type": "text", + "id": "hf9PE3HmRgXb" + }, + "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": 1047, + "metadata": {}, + "outputs": [], + "source": [ + "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_summer_all(summary_calculator):\n", + " def __init__(self,data):\n", + " self.__data=data\n", + " super().__init__(\"Sum_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(\"All_Sum_Grades\",value=grade_sum) " + ] + }, + { + "cell_type": "code", + "execution_count": 1048, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 1049, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l2_\",7))" + ] + }, + { + "cell_type": "code", + "execution_count": 1050, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l3_\",14))" + ] + }, + { + "cell_type": "code", + "execution_count": 1051, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l4_\",11))" + ] + }, + { + "cell_type": "code", + "execution_count": 1052, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"q1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 1053, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"e1_\",15))" + ] + }, + { + "cell_type": "code", + "execution_count": 1054, + "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", + "All_Sum_Grades: 170.5\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", + "All_Sum_Grades: 59.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", + "All_Sum_Grades: 155.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", + "All_Sum_Grades: 423.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", + "All_Sum_Grades: 236.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", + "All_Sum_Grades: 356.5\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", + "All_Sum_Grades: 255.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", + "All_Sum_Grades: 306.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", + "All_Sum_Grades: 319.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", + "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", + "All_Sum_Grades: 298.5\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", + "All_Sum_Grades: 475.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", + "All_Sum_Grades: 396.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", + "All_Sum_Grades: 352.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", + "All_Sum_Grades: 359.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", + "All_Sum_Grades: 325.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", + "All_Sum_Grades: 420.5\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.apply_summary(grade_summer_all(class_data))\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": 1055, + "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", + "All_Sum_Grades: 170.5\n", + "l3_sum 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", + "All_Sum_Grades: 59.0\n", + "l3_sum 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", + "All_Sum_Grades: 155.0\n", + "l3_sum Letter: C-\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", + "All_Sum_Grades: 423.0\n", + "l3_sum 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", + "All_Sum_Grades: 236.0\n", + "l3_sum Letter: C+\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", + "All_Sum_Grades: 356.5\n", + "l3_sum Letter: B+\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", + "All_Sum_Grades: 255.0\n", + "l3_sum Letter: D\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", + "All_Sum_Grades: 306.0\n", + "l3_sum Letter: F-\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", + "All_Sum_Grades: 319.0\n", + "l3_sum Letter: F-\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", + "All_Sum_Grades: 298.5\n", + "l3_sum Letter: F-\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", + "All_Sum_Grades: 475.0\n", + "l3_sum 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", + "All_Sum_Grades: 396.0\n", + "l3_sum 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", + "All_Sum_Grades: 352.0\n", + "l3_sum 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", + "All_Sum_Grades: 359.0\n", + "l3_sum 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", + "All_Sum_Grades: 325.0\n", + "l3_sum 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", + "All_Sum_Grades: 420.5\n", + "l3_sum Letter: A+\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"l3_sum\",max_grade=100))\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "V3xb0q_mRgXg" + }, + "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": 1056, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "-8SYTb3GRgXi" + }, + "outputs": [], + "source": [ + "# Your solution here\n", + "class calculator(alg): \n", + " def __init__(self,name):\n", + " #alg.__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))" + ] + }, + { + "cell_type": "code", + "execution_count": 1057, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l1_sum 10.0\n", + "STD of l1_sum 0.0\n" + ] + } + ], + "source": [ + "# Assignment 1\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"l1_sum\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"l1_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 1058, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l2_sum 51.09375\n", + "STD of l2_sum 21.05663401252679\n" + ] + } + ], + "source": [ + "# Assignment 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": 1059, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l3_sum 73.3125\n", + "STD of l3_sum 38.301792957379945\n" + ] + } + ], + "source": [ + "# Assignment 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": 1060, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of l4_sum 34.125\n", + "STD of l4_sum 30.421774685248064\n" + ] + } + ], + "source": [ + "# Assignment 1\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": 1061, + "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": 1062, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of e1_sum 82.6875\n", + "STD of e1_sum 42.937045121316864\n" + ] + } + ], + "source": [ + "# Mid Term Exam\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": 1063, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Mean of All_Sum_Grades 306.625\n", + "STD of All_Sum_Grades 106.41509232716946\n" + ] + } + ], + "source": [ + "# For all grades\n", + "a_grade_book.apply_calculator(mean_std_calculator(),grade_name=\"All_Sum_Grades\")\n", + "a_grade_book.print_Mean_STD(a_grade_book,\"All_Sum_Grades\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ge_DGgjDRgXn" + }, + "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": 1064, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "1xAp0Yl9RgXt" + }, + "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,\"D+\"),\n", + " (.63,\"D\"),\n", + " (.6,\"D-\"),\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", + " #return grade(self.__grade_name,value=self.__grades_definition[i][1])\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 1065, + "metadata": {}, + "outputs": [], + "source": [ + "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": 1066, + "metadata": {}, + "outputs": [], + "source": [ + "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": 1067, + "metadata": {}, + "outputs": [], + "source": [ + "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": 1068, + "metadata": {}, + "outputs": [], + "source": [ + "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": 1069, + "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: B\n", + "l3_sum: D\n", + "l4_sum: D+\n", + "q1_sum: 9.5\n", + "e1_sum: D+\n", + "All_Sum_Grades: 170.5\n", + "l3_sum 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: F\n", + "l3_sum: D-\n", + "l4_sum: D+\n", + "q1_sum: 0\n", + "e1_sum: D-\n", + "All_Sum_Grades: 59.0\n", + "l3_sum 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: F\n", + "l3_sum: C+\n", + "l4_sum: D+\n", + "q1_sum: 5.0\n", + "e1_sum: D\n", + "All_Sum_Grades: 155.0\n", + "l3_sum Letter: C-\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: B\n", + "l3_sum: B+\n", + "l4_sum: A\n", + "q1_sum: 10.0\n", + "e1_sum: B+\n", + "All_Sum_Grades: 423.0\n", + "l3_sum 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: C+\n", + "l3_sum: B-\n", + "l4_sum: C+\n", + "q1_sum: 0\n", + "e1_sum: D\n", + "All_Sum_Grades: 236.0\n", + "l3_sum Letter: C+\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: B+\n", + "l3_sum: B\n", + "l4_sum: B-\n", + "q1_sum: 9.5\n", + "e1_sum: B-\n", + "All_Sum_Grades: 356.5\n", + "l3_sum Letter: B+\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: B-\n", + "l3_sum: C+\n", + "l4_sum: C+\n", + "q1_sum: 10.0\n", + "e1_sum: D+\n", + "All_Sum_Grades: 255.0\n", + "l3_sum Letter: D\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: B+\n", + "l3_sum: C-\n", + "l4_sum: B\n", + "q1_sum: 10.0\n", + "e1_sum: C+\n", + "All_Sum_Grades: 306.0\n", + "l3_sum Letter: F-\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: C\n", + "l3_sum: C-\n", + "l4_sum: A-\n", + "q1_sum: 9.5\n", + "e1_sum: B\n", + "All_Sum_Grades: 319.0\n", + "l3_sum Letter: F-\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: B\n", + "l3_sum: D+\n", + "l4_sum: C+\n", + "q1_sum: 9.5\n", + "e1_sum: B+\n", + "All_Sum_Grades: 298.5\n", + "l3_sum Letter: F-\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: C+\n", + "l3_sum: A\n", + "l4_sum: A+\n", + "q1_sum: 0\n", + "e1_sum: A-\n", + "All_Sum_Grades: 475.0\n", + "l3_sum 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: B+\n", + "l3_sum: B\n", + "l4_sum: B\n", + "q1_sum: 10.0\n", + "e1_sum: B\n", + "All_Sum_Grades: 396.0\n", + "l3_sum 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: B\n", + "l3_sum: A-\n", + "l4_sum: D+\n", + "q1_sum: 10.0\n", + "e1_sum: B\n", + "All_Sum_Grades: 352.0\n", + "l3_sum 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: C+\n", + "l3_sum: A-\n", + "l4_sum: C+\n", + "q1_sum: 0\n", + "e1_sum: B\n", + "All_Sum_Grades: 359.0\n", + "l3_sum 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: B+\n", + "l3_sum: B\n", + "l4_sum: D+\n", + "q1_sum: 0\n", + "e1_sum: B\n", + "All_Sum_Grades: 325.0\n", + "l3_sum 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" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "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: B\n", + "l3_sum: B+\n", + "l4_sum: B\n", + "q1_sum: 9.5\n", + "e1_sum: A-\n", + "All_Sum_Grades: 420.5\n", + "l3_sum Letter: A+\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": 1070, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Datae1_sum: D+\n", + "Student 1 Student Datae1_sum: D-\n", + "Student 2 Student Datae1_sum: D\n", + "Student 3 Student Datae1_sum: B+\n", + "Student 4 Student Datae1_sum: D\n", + "Student 5 Student Datae1_sum: B-\n", + "Student 6 Student Datae1_sum: D+\n", + "Student 7 Student Datae1_sum: C+\n", + "Student 8 Student Datae1_sum: B\n", + "Student 9 Student Datae1_sum: B+\n", + "Student 10 Student Datae1_sum: A-\n", + "Student 11 Student Datae1_sum: B\n", + "Student 12 Student Datae1_sum: B\n", + "Student 13 Student Datae1_sum: B\n", + "Student 14 Student Datae1_sum: B\n", + "Student 15 Student Datae1_sum: A-\n" + ] + } + ], + "source": [ + "a_grade_book.print_grades(\"e1_sum\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "wlLk3gRoRgXz" + }, + "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": 1071, + "metadata": {}, + "outputs": [], + "source": [ + "class calculator_drop_lowest(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_dropped_lowest(calculator_drop_lowest):\n", + " def __init__(self,prefix,n,drop):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " self.__drop=drop\n", + " super().__init__(\"Sum_Grades_Dropped_Lowest\")\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", + " #return grade(self.__prefix+\"Sum_Grades_Except_Lowest\",value=grade_sum)\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+\"Sum_Grades_dropped_Lowest\",value=grade_sum)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1072, + "metadata": {}, + "outputs": [], + "source": [ + "# Creating new gradebook for better understanding \n", + "class_data=csv_reader(\"Data1401-Grades.csv\")\n", + "a_grade_book=grade_book(\"Data 1410\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + " #print(student_i,a_student_0.name())\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", + " #print(v)\n", + "\n", + " a_grade_book.add_student(a_student_0)" + ] + }, + { + "cell_type": "code", + "execution_count": 1073, + "metadata": {}, + "outputs": [], + "source": [ + "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", + "# For summing all grades starting with a prefix up to n and creates a new sum grade\n", + "class grade_summer1(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", + " lst = self.__prefix\n", + " l,m = lst.split(\"_\")\n", + " for i in l:\n", + " ls = i\n", + " lsm = int(ls)\n", + " \n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", + " return grade(\"grade_\"+str(lsm),value=grade_sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 1074, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer1(\"l1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 1075, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer1(\"l2_\",7))" + ] + }, + { + "cell_type": "code", + "execution_count": 1076, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer1(\"l3_\",14))" + ] + }, + { + "cell_type": "code", + "execution_count": 1077, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer1(\"l4_\",11))" + ] + }, + { + "cell_type": "code", + "execution_count": 1078, + "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", + "grade_1: 10.0\n", + "grade_2: 58.0\n", + "grade_3: 9.0\n", + "grade_4: 0\n", + "grade_Sum_Grades_dropped_Lowest: 68.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", + "grade_1: 10.0\n", + "grade_2: 0\n", + "grade_3: 0\n", + "grade_4: 0\n", + "grade_Sum_Grades_dropped_Lowest: 10.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", + "grade_1: 10.0\n", + "grade_2: 0\n", + "grade_3: 71.0\n", + "grade_4: 0\n", + "grade_Sum_Grades_dropped_Lowest: 81.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", + "grade_1: 10.0\n", + "grade_2: 62.0\n", + "grade_3: 102.0\n", + "grade_4: 75.0\n", + "grade_Sum_Grades_dropped_Lowest: 177.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", + "grade_1: 10.0\n", + "grade_2: 49.5\n", + "grade_3: 77.5\n", + "grade_4: 26.0\n", + "grade_Sum_Grades_dropped_Lowest: 127.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", + "grade_1: 10.0\n", + "grade_2: 69.0\n", + "grade_3: 89.0\n", + "grade_4: 35.0\n", + "grade_Sum_Grades_dropped_Lowest: 158.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", + "grade_1: 10.0\n", + "grade_2: 54.5\n", + "grade_3: 64.5\n", + "grade_4: 30.0\n", + "grade_Sum_Grades_dropped_Lowest: 119.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", + "grade_1: 10.0\n", + "grade_2: 69.0\n", + "grade_3: 40.0\n", + "grade_4: 51.0\n", + "grade_Sum_Grades_dropped_Lowest: 120.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", + "grade_1: 10.0\n", + "grade_2: 39.5\n", + "grade_3: 40.0\n", + "grade_4: 68.0\n", + "grade_Sum_Grades_dropped_Lowest: 108.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", + "grade_1: 10.0\n", + "grade_2: 60.0\n", + "grade_3: 26.0\n", + "grade_4: 27.0\n", + "grade_Sum_Grades_dropped_Lowest: 87.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", + "grade_1: 10.0\n", + "grade_2: 47.0\n", + "grade_3: 126.0\n", + "grade_4: 105.0\n", + "grade_Sum_Grades_dropped_Lowest: 231.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", + "grade_1: 10.0\n", + "grade_2: 68.5\n", + "grade_3: 97.5\n", + "grade_4: 51.0\n", + "grade_Sum_Grades_dropped_Lowest: 166.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", + "grade_1: 10.0\n", + "grade_2: 64.0\n", + "grade_3: 115.0\n", + "grade_4: 0\n", + "grade_Sum_Grades_dropped_Lowest: 179.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", + "grade_1: 10.0\n", + "grade_2: 49.5\n", + "grade_3: 114.5\n", + "grade_4: 25.0\n", + "grade_Sum_Grades_dropped_Lowest: 164.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", + "grade_1: 10.0\n", + "grade_2: 68.0\n", + "grade_3: 95.0\n", + "grade_4: 0\n", + "grade_Sum_Grades_dropped_Lowest: 163.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", + "grade_1: 10.0\n", + "grade_2: 59.0\n", + "grade_3: 106.0\n", + "grade_4: 53.0\n", + "grade_Sum_Grades_dropped_Lowest: 165.0\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "#Dropping the lowest lab\n", + "a_grade_book.apply_summary(grade_summer_dropped_lowest(\"grade_\",4,1))\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "8BvZj4WSRgX3" + }, + "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": 1079, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "fDBUYrBaRgX5" + }, + "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": 1080, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "YNHFW3azRgYE" + }, + "outputs": [], + "source": [ + "# Your solution here\n", + "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_averaged_letter_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 Based 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", + " #if not a_grade.numerical():\n", + " #print (self.name()+ \" Error: Did not get a numerical grade as input.\")\n", + " #raise Exception\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": 1081, + "metadata": {}, + "outputs": [], + "source": [ + "# Creating new gradebook for final grade calculation\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": 1082, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 1083, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l2_\",7))" + ] + }, + { + "cell_type": "code", + "execution_count": 1084, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l3_\",14))" + ] + }, + { + "cell_type": "code", + "execution_count": 1085, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"l4_\",11))" + ] + }, + { + "cell_type": "code", + "execution_count": 1086, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"q1_\",1))" + ] + }, + { + "cell_type": "code", + "execution_count": 1087, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_summary(grade_summer(\"e1_\",15))" + ] + }, + { + "cell_type": "code", + "execution_count": 1088, + "metadata": {}, + "outputs": [], + "source": [ + "# Since the final is not completed yet, however for the sake of calculation I assigned the same value for it as midterm\n", + "a_grade_book.apply_calculator(weighted_averaged_letter_grade(\"l1_sum\",\"l2_sum\",\"l3_sum\",\"l4_sum\",\"q1_sum\",\"e1_sum\",\"e1_sum\"),overwrite=False)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ixcvgkwtRgYD" + }, + "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": 1089, + "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": [ + "#Printing the final grade\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Lab-7.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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +} From 60aa7da86921709f79f36ae581662b8ed86a0e8a Mon Sep 17 00:00:00 2001 From: Md Arifur Rahman <51131568+mxr8032@users.noreply.github.com> Date: Sun, 10 May 2020 21:39:33 -0500 Subject: [PATCH 12/12] Final Exam Submission Md Arifur Rahman (1001618032) --- Exams/Final/Final-Submission.ipynb | 1097 ++++++++++++++++++++++++++++ 1 file changed, 1097 insertions(+) create mode 100644 Exams/Final/Final-Submission.ipynb diff --git a/Exams/Final/Final-Submission.ipynb b/Exams/Final/Final-Submission.ipynb new file mode 100644 index 0000000..a2e8f04 --- /dev/null +++ b/Exams/Final/Final-Submission.ipynb @@ -0,0 +1,1097 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "D9lBAAQnC2hH" + }, + "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": { + "colab_type": "text", + "id": "UxM8pJ2YC2hJ" + }, + "source": [ + "Recall the drawing system from lecture 18:" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "DPijqhxnC2hL" + }, + "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)\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": { + "colab": {}, + "colab_type": "code", + "id": "Na77rMSDC2ha" + }, + "outputs": [], + "source": [ + "class Shape:\n", + " def __init__(self, name=\"\", **kwargs):\n", + " self.name=name\n", + " self.kwargs=kwargs\n", + " \n", + " def paint(self, canvas): pass\n", + " \n", + " def __str__(self):\n", + " return '{}'.format(self.name)\n", + "\n", + "class Rectangle(Shape):\n", + " def __init__(self, x, y, w, h, **kwargs):\n", + " #Shape.__init__(self, **kwargs)\n", + " super().__init__(**kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.w = w\n", + " self.h = h\n", + "\n", + " def paint(self, canvas):\n", + " canvas.h_line(self.x, self.y, self.w, **self.kwargs)\n", + " canvas.h_line(self.x, self.y + self.h, self.w, **self.kwargs)\n", + " canvas.v_line(self.x, self.y, self.h, **self.kwargs)\n", + " canvas.v_line(self.x + self.w, self.y, self.h, **self.kwargs)\n", + "\n", + "class Square(Rectangle):\n", + " def __init__(self, x, y, size, **kwargs):\n", + " #Rectangle.__init__(self, x, y, size, size, **kwargs)\n", + " super().__init__(x, y, size, size, **kwargs)\n", + "\n", + "class Line(Shape):\n", + " def __init__(self, x1, y1, x2, y2, **kwargs):\n", + " #Shape.__init__(self, **kwargs)\n", + " super().__init__(**kwargs)\n", + " self.x1=x1\n", + " self.y1=y1\n", + " self.x2=x2\n", + " self.y2=y2\n", + " \n", + " def paint(self, canvas):\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2)\n", + " \n", + "class CompoundShape(Shape):\n", + " def __init__(self, shapes):\n", + " self.shapes = shapes\n", + "\n", + " def paint(self, canvas):\n", + " for s in self.shapes:\n", + " s.paint(canvas)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "class RasterDrawing():\n", + " def __init__(self):\n", + " self.shapes=dict()\n", + " self.shape_names=list()\n", + " \n", + " def add_shape(self,shape):\n", + " if shape.name == \"\":\n", + " shape.name = self.assign_name()\n", + " \n", + " self.shapes[shape.name]=shape\n", + " self.shape_names.append(shape.name)\n", + " \n", + " def paint(self,canvas):\n", + " for shape_name in self.shape_names:\n", + " self.shapes[shape_name].paint(canvas)\n", + " \n", + " def assign_name(self):\n", + " name_base=\"shape\"\n", + " name = name_base+\"_0\"\n", + " \n", + " i=1\n", + " while name in self.shapes:\n", + " name = name_base+\"_\"+name+\"_\"+str(i)\n", + " \n", + " return name\n", + " \n", + " def save(self,filename):\n", + " self.filename = filename\n", + " file = open(self.filename,'a')\n", + " for shap_nam in self.shapes.keys():\n", + " #file.write(\"{}\\n\".format(shap_nam))\n", + " file.write(shap_nam)\n", + " file.write(\"\\n\")\n", + " file.close()\n", + " \n", + " def load(self,filename):\n", + " self.filename = filename\n", + " file=open(self.filename,\"r\")\n", + " can=Canvas(50,50)\n", + " ras = RasterDrawing()\n", + " for shape in file:\n", + " ras.add_shape(eval(shape))\n", + " ras.paint(can)\n", + " can.display()\n", + "\n", + " file.close()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "Vz8zppAeC2ic" + }, + "source": [ + "1. Add `Point` and `Triangle` classes and test them." + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "gBerd7eRC2id" + }, + "outputs": [], + "source": [ + "class Point(Shape):\n", + " def __init__(self,x,y,**kwargs):\n", + " self.x = x\n", + " self.y = y\n", + " self.kwargs=kwargs\n", + " Shape.__init__(self, **kwargs)\n", + " def paint(self, canvas):\n", + " canvas.set_pixel(self.x, self.y, **self.kwargs)\n", + "\n", + "class Triangle(Shape):\n", + " def __init__(self, x1,y1, x2,y2, x3,y3, **kwargs):\n", + " #Shape.__init__(self, **kwargs)\n", + " super().__init__(**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.kwargs=kwargs\n", + " \n", + " def paint(self, canvas):\n", + " if self.y2==self.y1:\n", + " canvas.h_line(self.x1, self.y1, abs(self.x1-self.x2), **self.kwargs)\n", + " if self.x2==self.x1:\n", + " canvas.v_line(self.x1, self.y1, abs(self.y1-self.y2), **self.kwargs)\n", + " if self.y2==self.y3:\n", + " canvas.h_line(self.x3, self.y3, abs(self.x2-self.x3), **self.kwargs)\n", + " if self.x2==self.x3:\n", + " canvas.v_line(self.x3, self.y3, abs(self.y2-self.y3), **self.kwargs)\n", + " if self.y3==self.y1:\n", + " canvas.h_line(self.x1, self.y1, abs(self.x1-self.x3), **self.kwargs)\n", + " if self.x3==self.x1:\n", + " canvas.v_line(self.x1, self.y1, abs(self.y1-self.y3), **self.kwargs)\n", + " \n", + " if self.y2!=self.y1 and self.x2!=self.x1:\n", + " canvas.line(self.x1, self.y1, self.x2, self.y2)\n", + " \n", + " if self.y2!=self.y3 and self.x2!=self.x3: \n", + " canvas.line(self.x3, self.y3, self.x2, self.y2)\n", + " \n", + " if self.y3!=self.y1 and self.x3!=self.x1:\n", + " canvas.line(self.x1, self.y1, self.x3, self.y3)" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [], + "source": [ + "a_canvas = Canvas(10,10)" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " \n", + " \n", + " \n", + " \n", + " \n", + " * \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "pt = Point(5,5)\n", + "pt.paint(a_canvas)\n", + "a_canvas.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [], + "source": [ + "b_canvas = Canvas(40,40)" + ] + }, + { + "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", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n" + ] + } + ], + "source": [ + "tr = Triangle(0,0, 20,0, 10,20)\n", + "tr.paint(b_canvas)\n", + "b_canvas.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "tOAmd1LiC2il" + }, + "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": 9, + "metadata": {}, + "outputs": [], + "source": [ + "import math\n", + "class Arc(Shape):\n", + " def __init__(self, h,k, a, b ,str_ang=None,end_ang=None,**kwargs):\n", + " #Shape.__init__(self, **kwargs)\n", + " super().__init__(**kwargs)\n", + " self.h = h\n", + " self.k = k\n", + " self.a = a\n", + " self.b= b\n", + " self.str_ang = str_ang\n", + " self.end_ang = end_ang\n", + " self.kwargs=kwargs\n", + " \n", + " \n", + " def paint(self, canvas):\n", + " if self.a == self.b and (self.str_ang + self.end_ang)==360:\n", + " for theta in range(self.str_ang,self.end_ang+1):\n", + " x = int(self.h + self.a*math.cos(theta))\n", + " y = int(self.k + self.a*math.sin(theta))\n", + " canvas.set_pixel(x,y)\n", + " \n", + " elif self.a == self.b and (self.str_ang + self.end_ang)<360:\n", + " for theta in range(self.str_ang,self.end_ang+1):\n", + " x = int(self.h + self.a*math.cos(theta))\n", + " y = int(self.k + self.a*math.sin(theta))\n", + " canvas.set_pixel(x,y)\n", + " \n", + " elif self.a > self.b and self.str_ang +self.end_ang==360:\n", + " for x in range(self.h-self.a,self.k+self.a+1):\n", + " y = int(self.h+self.b*math.sqrt(1-((x-self.h)/self.a)**2))\n", + " canvas.set_pixel(x,y)\n", + " y1 = -y\n", + " canvas.set_pixel(x,y1)\n", + " \n", + " elif self.a > self.b and self.str_ang +self.end_ang<360:\n", + " for y in range(self.k-self.b,self.k+self.b+1):\n", + " x = int(self.h+self.b*math.sqrt(1-((y-self.k)/self.a)**2))\n", + " canvas.set_pixel(x,y)\n", + " " + ] + }, + { + "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" + ] + } + ], + "source": [ + "# Arc\n", + "e_canvas = Canvas(20,20)\n", + "arc = Arc(5,10,10,8,0,180)\n", + "arc.paint(e_canvas)\n", + "e_canvas.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": {}, + "outputs": [], + "source": [ + "class circle(Arc):\n", + " def __init__(self,h,k, r ,str_ang,end_ang,**kwargs):\n", + " super().__init__(h,k, r, r ,str_ang,end_ang,**kwargs)\n", + " \n", + "class oval(Arc):\n", + " def __init__(self,h,k, a, b ,str_ang=None,end_ang=None,**kwargs):\n", + " super().__init__(h,k, a, b ,str_ang,end_ang,**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "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" + ] + } + ], + "source": [ + "#Circle\n", + "e_canvas = Canvas(40,40)\n", + "cir = circle(20,20,15,0,360)\n", + "cir.paint(e_canvas)\n", + "e_canvas.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "metadata": { + "scrolled": false + }, + "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" + ] + } + ], + "source": [ + "# Oval\n", + "f_canvas = Canvas(40,40)\n", + "ovl = oval(20,20,15,10,0,360)\n", + "ovl.paint(f_canvas)\n", + "f_canvas.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "BBrVf9PsC2iv" + }, + "source": [ + "3. Use your classes to create a `RasterDrawing` that draws a happy face." + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "can=Canvas(50,50)\n", + "rd=RasterDrawing()" + ] + }, + { + "cell_type": "code", + "execution_count": 15, + "metadata": {}, + "outputs": [], + "source": [ + "rd.add_shape(circle(25,25,20,0,360))\n", + "rd.add_shape(Square(15,12,4))" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [], + "source": [ + "rd.add_shape(Square(15,33,4))\n", + "rd.add_shape(circle(25,25,1.4,0,360))" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [], + "source": [ + "rd.add_shape(Rectangle(14,12, 1,4))\n", + "rd.add_shape(Rectangle(14,33, 1,4))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [], + "source": [ + "rd.add_shape(Rectangle(34,20, 2,10))\n", + "rd.add_shape(Arc(30,24,8,7,0,180))" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "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": [ + "rd.paint(can)\n", + "can.display()" + ] + }, + { + "cell_type": "code", + "execution_count": 20, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "PXwrtwLiC2ix" + }, + "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": [ + "hface=Canvas(50,50)\n", + "cshape=CompoundShape([circle(25,25,20,0,360),Square(15,12,4),Square(15,33,4),Rectangle(14,12, 1,4),Rectangle(14,33, 1,4),circle(25,25,1.4,0,360),Arc(30,24,8,7,0,180),Rectangle(34,20, 2,10)])\n", + "cshape.paint(hface)\n", + "hface.display()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "PO_YkmzOC2i3" + }, + "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": 21, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "P7ntIrGQC2i7" + }, + "outputs": [], + "source": [ + "sq = Shape(\"Square(15,12,4)\")\n", + "rc = Shape(\"Rectangle(10,10,15,12)\")\n", + "tr = Shape(\"Triangle(0,0, 20,0, 10,20)\")\n", + "cr = Shape(\"circle(25,25,20,0,360)\")\n", + "ar = Shape(\"Arc(30,24,8,7,0,180)\")\n", + "ov = Shape(\"oval(20,20,15,10,0,360)\") " + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Square(15,12,4)'" + ] + }, + "execution_count": 22, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "sq.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Rectangle(10,10,15,12)'" + ] + }, + "execution_count": 23, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rc.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Triangle(0,0, 20,0, 10,20)'" + ] + }, + "execution_count": 24, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "tr.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 25, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'circle(25,25,20,0,360)'" + ] + }, + "execution_count": 25, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "cr.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'Arc(30,24,8,7,0,180)'" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ar.__str__()" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "'oval(20,20,15,10,0,360)'" + ] + }, + "execution_count": 27, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "ov.__str__()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "jalCs3pbC2jA" + }, + "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": [ + "rp = RasterDrawing()" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [], + "source": [ + "rp.add_shape(Shape(\"circle(25,25,20,0,360)\"))\n", + "rp.add_shape(Shape(\"Square(15,12,4)\"))\n", + "rp.add_shape(Shape(\"Square(15,33,4)\"))\n", + "rp.add_shape(Shape(\"circle(25,25,1.4,0,360)\"))\n", + "rp.add_shape(Shape(\"Arc(30,24,8,7,0,180)\"))\n", + "rp.add_shape(Shape(\"Rectangle(14,12, 1,4)\"))\n", + "rp.add_shape(Shape(\"Rectangle(14,33, 1,4)\"))\n", + "rp.add_shape(Shape(\"Rectangle(34,20, 2,10)\"))" + ] + }, + { + "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,33,4)', 'circle(25,25,1.4,0,360)', 'Arc(30,24,8,7,0,180)', 'Rectangle(14,12, 1,4)', 'Rectangle(14,33, 1,4)', 'Rectangle(34,20, 2,10)'])" + ] + }, + "execution_count": 30, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "rp.shapes.keys()" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [], + "source": [ + "rp.save(\"Shape_list.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(\"Shape_list.txt\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Final.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.6" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}