diff --git a/Copy_of_Lab_1.ipynb b/Copy_of_Lab_1.ipynb new file mode 100644 index 0000000..24702d4 --- /dev/null +++ b/Copy_of_Lab_1.ipynb @@ -0,0 +1,2121 @@ +{ + "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": "wJuFIPY71ZrP", + "colab_type": "code", + "outputId": "e1b11a80-a161-42ee-cf39-bce154a827ab", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + } + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FVt_1hPt1dAK", + "colab_type": "text" + }, + "source": [ + "## Notebooks in Colab\n", + "\n", + "You now are presumably in Colab. Word of caution, by default, Google Colab does not save your notebooks, so if you close your session, you will loose your work.\n", + "\n", + "So first thing: from the file menu above select \"Save a copy in Drive\"." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x0JBL_RFrDDj", + "colab_type": "text" + }, + "source": [ + "## Storing Notebooks in Google Drive\n", + "A better way to work is to save your notebooks directly into Google Drive and upload directly to Git (where you will be downloading and uploading your homework). In order properly setup Git, we'll need to work more directly in your Google Drive.\n", + "\n", + "On the left sidebar, press the file icon to see a listing of files accessibile to this Notebook. Then press \"Mount Drive\" and follow the instructions to mount your Google Drive in this notebook. A new cell will be inserted into this notebook, which after you run by pressing the play button will instruct you to follow a link to log into your Google Account and enable access to your Drive in another tab. Finally you will copy a link from the new tab back into the cell in this notebook. Once you are done, press refresh under files in the left sidebar and you should have \"drive/My Drive\" appear." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hwJ6wJk3tiLv", + "colab_type": "text" + }, + "source": [ + "## Github\n", + "All the class material will be stored on github. You will also submit your homework using github. To do so, you will need a github account.\n", + "\n", + "If you do not already have a github account or wish to create a new one for this course, create one:\n", + "* Browse to [github.com](https://github.com).\n", + "* Click the green “Sign up for GitHub”\tbutton.\n", + "* Follow instructions for creating an account.\n", + "* Make sure you remember your github username and password.\n", + "\n", + "Write an email to the course TA titled \"Data 1401: Github account\" with your github username (not your password) as the contents.\n", + "\n", + "## Google Groups\n", + "\n", + "Class annoucements will be made via google groups. If you did not already receive an invite to the class google group, had trouble with the invite, or wish to use a different email address, write an email to the course TA titled \"Data 1401: Google Group\" with your preferred email.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TjfIzdQZqvzk", + "colab_type": "text" + }, + "source": [ + "## Introduction: Unix, Git, and Jupyter\n", + "\n", + "This lab aims to introduce you to basic Unix, familiarize you with iPython notebooks and get you setup to submit your homework.\n", + "*italicized text*" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C_LmOgzFqvzp", + "colab_type": "text" + }, + "source": [ + "\n", + "\n", + "### Terminal, Shell, and ssh\n", + "\n", + "\n", + "The terminal is a simple program that generally runs another program, taking mostly keyboard input from you, passing it to this other program, and taking the output of the program and displaying on the screen for you.\n", + "\n", + "The terminal usually runs a program called a shell. Shells present a command prompt where you can type in commands, which are then executed when you press enter. In most shells, there are some special commands which the shell will execute. Everything else you type in, the shell will assume is a name of a program you want to run and arguments you want to pass that program. So if the shell doesn't recognize something you type in, it'll try to find a program with a name that is the same as the first word you gave it. \n", + "\n", + "### Shell in Colab\n", + "\n", + "Unfortunately, google Colab does not allow you to open a terminal window. Jupyter does, so if you are running in Jupyter (which most of you will not be), you may choose to open a terminal window by returning to the jupyter file list tab and selecting new terminal from the top right.\n", + "\n", + "For Colab, we will have to do something non-ideal, but functional. There are several ways to execute shell commands from within a python notebook. For example, you can use any shell command by putting \"!\" in front of the command:\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "KJ5f-WO0wcAv", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!ls\n", + "!echo \"----------\"\n", + "!ls sample_data" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "source": [ + "!echo \"Technique 1:\"\n", + "!ls\n", + "!cd sample_data\n", + "!ls" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "2-Znf97Lxl-Z", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!echo \"Technique 2:\"\n", + "!ls ; cd sample_data ;ls" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "source": [ + "!echo \"Technique 3:\"\n", + "!ls \n", + "%cd sample_data \n", + "!ls" + ], + "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": "code", + "metadata": { + "id": "MIDFitLZyuZy", + "colab_type": "code", + "outputId": "67f17d93-ed37-477b-e07b-a84ad94f182d", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "!/bin/bash --noediting\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mdrive\u001b[0m favoritecolors \u001b[01;34msample_data\u001b[0m sorted_favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd sample_data\n", + "\u001b]0;root@47551fbb9a44: /content/sample_data\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# pwd\n", + "/content/sample_data\n", + "\u001b]0;root@47551fbb9a44: /content/sample_data\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q-4hfZBywW25", + "colab_type": "text" + }, + "source": [ + "While in this instance your shell is running in a this notebook, you can also run terminals natively on your own computer. On Linux or MacOS, you just have to run a program called terminal. In Windows you can start a \"command prompt\". \n", + "\n", + "\n", + "Type in \"ls\" into the terminal and press enter. The shell will find a program called \"ls\", a standard tool in Unix, and run it. \"ls\" lists the contents (files and directories) of your current directory. If you are just starting in this course, you probably only see the git repository you cloned. \n", + "\n", + "A subtle point to realize here is that while the terminal is running in the browser that is running on the computer in front of you, the shell is actually running on a machine on google hardware. The shell prompt typically displays the name of the machine you are using. What you are not seeing is that there is an intermidate program between the terminal running on your computer and the shell running on google. This intermidary program is taking your input from the terminal sending it over the network to google and bringing back the responses for you terminal to display.\n", + "\n", + "A bit of extra information. If you start a terminal on your own computer, the shell runs locally. The \"ls\" command would then list contents of a directory on your computer. You can typically connect to Unix computers by evoking a shell running on that machine over the network. In this case, you would have to initiate this intermidiary program yourself. The program is called \"ssh\" (secure shell). You can \"ssh\" to another machine from your machine, by simply typing \"ssh\" followed by the machine name or IP address. Most likely you would be prompted for a password, after which you would dropped into the prompt of a shell running on the remote machine. \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "51Eya4LBqvzs", + "colab_type": "text" + }, + "source": [ + "## Programs and Environment Variables\n", + "\n", + "You have a listing of your current directory, but you don't know where that directory resides. You can see what directory you are using the command \"pwd\" (print working directory). Issue the command and look at the response. You'll get a slash (\"/\") separated list, known as the path, of the directory hierarchy of your current working directory. On Colab, this will start with \"contents\"\n", + "\n", + "Now back to thinking about the command prompt. Since \"ls\" is a program, it most be stored somewhere. It is clearly not in your working directory, because you didn't see it when you executed \"ls\". We can ask the shell to tell us where it found \"ls\" using the \"which ls\" command. Note that \"which\" is also a program. \"which ls\" comes back with \"/bin/ls\", telling you the \"ls\" program is sitting in \"/bin\" directory of the system. \n", + "\n", + "Lets see what else is in there by issuing a \"ls /bin\" command. You will get a long list of programs. You can run any of these programs by just typing their names and pressing enter. You may be able to guess what some of these programs do, but if you want to know, most of them provide you help, using \"--help\" or \"-h\" flag. For example execute \"ls --help\". For more information about a program or command, you can use Unix's manual pages using the \"man\" command. Try typing \"man ls\". Note that you will need to press space to scroll through lengthy manual pages and \"q\" to exit back to the shell prompt. \n", + "\n", + "Another command interesting is \"echo\". \"echo\" simply prints whatever you put after it to the screen. Try executing \"echo Hello World.\"\n", + "\n", + "At this point, you may wonder how was it that the shell knew to look for programs in \"/bin\"? The shell keeps a list of places to look for programs an environment variable with the name \"PATH\". The shell keeps a table that map string variable names to string expressions. When the shell starts, its configuration files set some environment variables that it uses. You can see the full list of defined environment variables using the command \"printenv\".\n", + "\n", + "You can use a environment variable in a shell by prepending name of the variable with a dollar sign character (\"\\$\"). So you can print out the PATH environment variable using the command \"echo $PATH\". What you will see is a colon (\":\") separated list of directories that the shell will search (in order) whenever you type in anything.\n", + "\n", + "You can set you own environment variables. Different shells have different syntax. Lets first figure out what shell we are running. \n", + "\n", + "*Exercise 1:* Use the \"echo\" command to print out the value of the \"SHELL\" environment variable:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YS7YFiPwqvzu", + "colab_type": "text" + }, + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vkQmmbcjsdPx", + "colab_type": "code", + "outputId": "eeaf6893-38ab-4569-a21a-60b01016f665", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (123): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# pwd\n", + "/content\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# which ls\n", + "/bin/ls\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls/bin\n", + "bash: ls/bin: No such file or directory\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /bin\n", + "\u001b[0m\u001b[01;32mbash\u001b[0m \u001b[01;32mjournalctl\u001b[0m \u001b[01;32msync\u001b[0m\n", + "\u001b[01;32mbunzip2\u001b[0m \u001b[01;32mkill\u001b[0m \u001b[01;32msystemctl\u001b[0m\n", + "\u001b[01;32mbzcat\u001b[0m \u001b[01;32mkmod\u001b[0m \u001b[01;36msystemd\u001b[0m\n", + "\u001b[01;36mbzcmp\u001b[0m \u001b[01;32mless\u001b[0m \u001b[01;32msystemd-ask-password\u001b[0m\n", + "\u001b[01;32mbzdiff\u001b[0m \u001b[01;32mlessecho\u001b[0m \u001b[01;32msystemd-escape\u001b[0m\n", + "\u001b[01;36mbzegrep\u001b[0m \u001b[01;36mlessfile\u001b[0m \u001b[01;32msystemd-hwdb\u001b[0m\n", + "\u001b[01;32mbzexe\u001b[0m \u001b[01;32mlesskey\u001b[0m \u001b[01;32msystemd-inhibit\u001b[0m\n", + "\u001b[01;36mbzfgrep\u001b[0m \u001b[01;32mlesspipe\u001b[0m \u001b[01;32msystemd-machine-id-setup\u001b[0m\n", + "\u001b[01;32mbzgrep\u001b[0m \u001b[01;32mln\u001b[0m \u001b[01;32msystemd-notify\u001b[0m\n", + "\u001b[01;32mbzip2\u001b[0m \u001b[01;32mlogin\u001b[0m \u001b[01;32msystemd-sysusers\u001b[0m\n", + "\u001b[01;32mbzip2recover\u001b[0m \u001b[01;32mloginctl\u001b[0m \u001b[01;32msystemd-tmpfiles\u001b[0m\n", + "\u001b[01;36mbzless\u001b[0m \u001b[01;32mls\u001b[0m \u001b[01;32msystemd-tty-ask-password-agent\u001b[0m\n", + "\u001b[01;32mbzmore\u001b[0m \u001b[01;32mlsblk\u001b[0m \u001b[01;32mtar\u001b[0m\n", + "\u001b[01;32mcat\u001b[0m \u001b[01;36mlsmod\u001b[0m \u001b[01;32mtempfile\u001b[0m\n", + "\u001b[01;32mchgrp\u001b[0m \u001b[01;32mmkdir\u001b[0m \u001b[01;32mtouch\u001b[0m\n", + "\u001b[01;32mchmod\u001b[0m \u001b[01;32mmknod\u001b[0m \u001b[01;32mtrue\u001b[0m\n", + "\u001b[01;32mchown\u001b[0m \u001b[01;32mmktemp\u001b[0m \u001b[01;32mudevadm\u001b[0m\n", + "\u001b[01;32mcp\u001b[0m \u001b[01;32mmore\u001b[0m \u001b[01;32mulockmgr_server\u001b[0m\n", + "\u001b[01;32mdash\u001b[0m \u001b[37;41mmount\u001b[0m \u001b[37;41mumount\u001b[0m\n", + "\u001b[01;32mdate\u001b[0m \u001b[01;32mmountpoint\u001b[0m \u001b[01;32muname\u001b[0m\n", + "\u001b[01;32mdd\u001b[0m \u001b[01;32mmv\u001b[0m \u001b[01;32muncompress\u001b[0m\n", + "\u001b[01;32mdf\u001b[0m \u001b[01;32mnetworkctl\u001b[0m \u001b[01;32mvdir\u001b[0m\n", + "\u001b[01;32mdir\u001b[0m \u001b[01;36mnisdomainname\u001b[0m \u001b[01;32mwdctl\u001b[0m\n", + "\u001b[01;32mdmesg\u001b[0m \u001b[01;36mpidof\u001b[0m \u001b[01;32mwhich\u001b[0m\n", + "\u001b[01;36mdnsdomainname\u001b[0m \u001b[01;32mps\u001b[0m \u001b[01;36mypdomainname\u001b[0m\n", + "\u001b[01;36mdomainname\u001b[0m \u001b[01;32mpwd\u001b[0m \u001b[01;32mzcat\u001b[0m\n", + "\u001b[01;32mecho\u001b[0m \u001b[01;36mrbash\u001b[0m \u001b[01;32mzcmp\u001b[0m\n", + "\u001b[01;32megrep\u001b[0m \u001b[01;32mreadlink\u001b[0m \u001b[01;32mzdiff\u001b[0m\n", + "\u001b[01;32mfalse\u001b[0m \u001b[01;32mrm\u001b[0m \u001b[01;32mzegrep\u001b[0m\n", + "\u001b[01;32mfgrep\u001b[0m \u001b[01;32mrmdir\u001b[0m \u001b[01;32mzfgrep\u001b[0m\n", + "\u001b[01;32mfindmnt\u001b[0m \u001b[01;32mrun-parts\u001b[0m \u001b[01;32mzforce\u001b[0m\n", + "\u001b[37;41mfusermount\u001b[0m \u001b[01;32msed\u001b[0m \u001b[01;32mzgrep\u001b[0m\n", + "\u001b[01;32mgrep\u001b[0m \u001b[01;36msh\u001b[0m \u001b[01;32mzless\u001b[0m\n", + "\u001b[01;32mgunzip\u001b[0m \u001b[01;36msh.distrib\u001b[0m \u001b[01;32mzmore\u001b[0m\n", + "\u001b[01;32mgzexe\u001b[0m \u001b[01;32msleep\u001b[0m \u001b[01;32mznew\u001b[0m\n", + "\u001b[01;32mgzip\u001b[0m \u001b[01;32mstty\u001b[0m\n", + "\u001b[01;32mhostname\u001b[0m \u001b[37;41msu\u001b[0m\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls --help\n", + "Usage: ls [OPTION]... [FILE]...\n", + "List information about the FILEs (the current directory by default).\n", + "Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n", + "\n", + "Mandatory arguments to long options are mandatory for short options too.\n", + " -a, --all do not ignore entries starting with .\n", + " -A, --almost-all do not list implied . and ..\n", + " --author with -l, print the author of each file\n", + " -b, --escape print C-style escapes for nongraphic characters\n", + " --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\n", + " '--block-size=M' prints sizes in units of\n", + " 1,048,576 bytes; see SIZE format below\n", + " -B, --ignore-backups do not list implied entries ending with ~\n", + " -c with -lt: sort by, and show, ctime (time of last\n", + " modification of file status information);\n", + " with -l: show ctime and sort by name;\n", + " otherwise: sort by ctime, newest first\n", + " -C list entries by columns\n", + " --color[=WHEN] colorize the output; WHEN can be 'always' (default\n", + " if omitted), 'auto', or 'never'; more info below\n", + " -d, --directory list directories themselves, not their contents\n", + " -D, --dired generate output designed for Emacs' dired mode\n", + " -f do not sort, enable -aU, disable -ls --color\n", + " -F, --classify append indicator (one of */=>@|) to entries\n", + " --file-type likewise, except do not append '*'\n", + " --format=WORD across -x, commas -m, horizontal -x, long -l,\n", + " single-column -1, verbose -l, vertical -C\n", + " --full-time like -l --time-style=full-iso\n", + " -g like -l, but do not list owner\n", + " --group-directories-first\n", + " group directories before files;\n", + " can be augmented with a --sort option, but any\n", + " use of --sort=none (-U) disables grouping\n", + " -G, --no-group in a long listing, don't print group names\n", + " -h, --human-readable with -l and/or -s, print human readable sizes\n", + " (e.g., 1K 234M 2G)\n", + " --si likewise, but use powers of 1000 not 1024\n", + " -H, --dereference-command-line\n", + " follow symbolic links listed on the command line\n", + " --dereference-command-line-symlink-to-dir\n", + " follow each command line symbolic link\n", + " that points to a directory\n", + " --hide=PATTERN do not list implied entries matching shell PATTERN\n", + " (overridden by -a or -A)\n", + " --hyperlink[=WHEN] hyperlink file names; WHEN can be 'always'\n", + " (default if omitted), 'auto', or 'never'\n", + " --indicator-style=WORD append indicator with style WORD to entry names:\n", + " none (default), slash (-p),\n", + " file-type (--file-type), classify (-F)\n", + " -i, --inode print the index number of each file\n", + " -I, --ignore=PATTERN do not list implied entries matching shell PATTERN\n", + " -k, --kibibytes default to 1024-byte blocks for disk usage\n", + " -l use a long listing format\n", + " -L, --dereference when showing file information for a symbolic\n", + " link, show information for the file the link\n", + " references rather than for the link itself\n", + " -m fill width with a comma separated list of entries\n", + " -n, --numeric-uid-gid like -l, but list numeric user and group IDs\n", + " -N, --literal print entry names without quoting\n", + " -o like -l, but do not list group information\n", + " -p, --indicator-style=slash\n", + " append / indicator to directories\n", + " -q, --hide-control-chars print ? instead of nongraphic characters\n", + " --show-control-chars show nongraphic characters as-is (the default,\n", + " unless program is 'ls' and output is a terminal)\n", + " -Q, --quote-name enclose entry names in double quotes\n", + " --quoting-style=WORD use quoting style WORD for entry names:\n", + " literal, locale, shell, shell-always,\n", + " shell-escape, shell-escape-always, c, escape\n", + " -r, --reverse reverse order while sorting\n", + " -R, --recursive list subdirectories recursively\n", + " -s, --size print the allocated size of each file, in blocks\n", + " -S sort by file size, largest first\n", + " --sort=WORD sort by WORD instead of name: none (-U), size (-S),\n", + " time (-t), version (-v), extension (-X)\n", + " --time=WORD with -l, show time as WORD instead of default\n", + " modification time: atime or access or use (-u);\n", + " ctime or status (-c); also use specified time\n", + " as sort key if --sort=time (newest first)\n", + " --time-style=STYLE with -l, show times using style STYLE:\n", + " full-iso, long-iso, iso, locale, or +FORMAT;\n", + " FORMAT is interpreted like in 'date'; if FORMAT\n", + " is FORMAT1FORMAT2, then FORMAT1 applies\n", + " to non-recent files and FORMAT2 to recent files;\n", + " if STYLE is prefixed with 'posix-', STYLE\n", + " takes effect only outside the POSIX locale\n", + " -t sort by modification time, newest first\n", + " -T, --tabsize=COLS assume tab stops at each COLS instead of 8\n", + " -u with -lt: sort by, and show, access time;\n", + " with -l: show access time and sort by name;\n", + " otherwise: sort by access time, newest first\n", + " -U do not sort; list entries in directory order\n", + " -v natural sort of (version) numbers within text\n", + " -w, --width=COLS set output width to COLS. 0 means no limit\n", + " -x list entries by lines instead of by columns\n", + " -X sort alphabetically by entry extension\n", + " -Z, --context print any security context of each file\n", + " -1 list one file per line. Avoid '\\n' with -q or -b\n", + " --help display this help and exit\n", + " --version output version information and exit\n", + "\n", + "The SIZE argument is an integer and optional unit (example: 10K is 10*1024).\n", + "Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).\n", + "\n", + "Using color to distinguish file types is disabled both by default and\n", + "with --color=never. With --color=auto, ls emits color codes only when\n", + "standard output is connected to a terminal. The LS_COLORS environment\n", + "variable can change the settings. Use the dircolors command to set it.\n", + "\n", + "Exit status:\n", + " 0 if OK,\n", + " 1 if minor problems (e.g., cannot access subdirectory),\n", + " 2 if serious trouble (e.g., cannot access command-line argument).\n", + "\n", + "GNU coreutils online help: \n", + "Full documentation at: \n", + "or available locally via: info '(coreutils) ls invocation'\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# man ls\n", + "LS(1POSIX) POSIX Programmer's Manual LS(1POSIX)\n", + "\n", + "P\bPR\bRO\bOL\bLO\bOG\bG\n", + " This manual page is part of the POSIX Programmer's Manual. The Linux\n", + " implementation of this interface may differ (consult the corresponding\n", + " Linux manual page for details of Linux behavior), or the interface may\n", + " not be implemented on Linux.\n", + "\n", + "N\bNA\bAM\bME\bE\n", + " ls — list directory contents\n", + "\n", + "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS\n", + " ls [\b[−ikqrs]\b] [\b[−glno]\b] [\b[−A|−a]\b] [\b[−C|−m|−x|−1]\b] \\\n", + " [\b[−F|−p]\b] [\b[−H|−L]\b] [\b[−R|−d]\b] [\b[−S|−f|−t]\b] [\b[−c|−u]\b] [\b[_\bf_\bi_\bl_\be...]\b]\n", + "\n", + "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\n", + " For each operand that names a file of a type other than directory or\n", + " symbolic link to a directory, _\bl_\bs shall write the name of the file as\n", + " well as any requested, associated information. For each operand that\n", + " names a file of type directory, _\bl_\bs shall write the names of files con‐\n", + " tained within the directory as well as any requested, associated infor‐\n", + " mation. Filenames beginning with a ('\b'.\b.'\b') and any associated\n", + " information shall not be written out unless explicitly referenced, the\n", + " −\b−A\bA or −\b−a\ba option is supplied, or an implementation-defined condition\n", + " causes them to be written. If one or more of the −\b−d\bd, −\b−F\bF, or −\b−l\bl options\n", + " are specified, and neither the −\b−H\bH nor the −\b−L\bL option is specified, for\n", + " each operand that names a file of type symbolic link to a directory, _\bl_\bs\n", + " shall write the name of the file as well as any requested, associated\n", + " information. If none of the −\b−d\bd, −\b−F\bF, or −\b−l\bl options are specified, or the\n", + " −\b−H\bH or −\b−L\bL options are specified, for each operand that names a file of\n", + " type symbolic link to a directory, _\bl_\bs shall write the names of files\n", + " contained within the directory as well as any requested, associated\n", + " information. In each case where the names of files contained within a\n", + " directory are written, if the directory contains any symbolic links\n", + " then _\bl_\bs shall evaluate the file information and file type to be those\n", + " of the symbolic link itself, unless the −\b−L\bL option is specified.\n", + "\n", + " If no operands are specified, _\bl_\bs shall behave as if a single operand of\n", + " dot ('\b'.\b.'\b') had been specified. If more than one operand is specified,\n", + " _\bl_\bs shall write non-directory operands first; it shall sort directory\n", + " and non-directory operands separately according to the collating\n", + " sequence in the current locale.\n", + "\n", + " The _\bl_\bs utility shall detect infinite loops; that is, entering a previ‐\n", + " ously visited directory that is an ancestor of the last file encoun‐\n", + " tered. When it detects an infinite loop, _\bl_\bs shall write a diagnostic\n", + " message to standard error and shall either recover its position in the\n", + " hierarchy or terminate.\n", + "\n", + "O\bOP\bPT\bTI\bIO\bON\bNS\bS\n", + " The _\bl_\bs utility shall conform to the Base Definitions volume of\n", + " POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b1_\b2_\b._\b2, _\bU_\bt_\bi_\bl_\bi_\bt_\by _\bS_\by_\bn_\bt_\ba_\bx _\bG_\bu_\bi_\bd_\be_\bl_\bi_\bn_\be_\bs.\n", + "\n", + " The following options shall be supported:\n", + "\n", + " −\b−A\bA Write out all directory entries, including those whose names\n", + " begin with a ('\b'.\b.'\b') but excluding the entries dot\n", + " and dot-dot (if they exist).\n", + "\n", + " −\b−C\bC Write multi-text-column output with entries sorted down the\n", + " columns, according to the collating sequence. The number of\n", + " text columns and the column separator characters are unspeci‐\n", + " fied, but should be adapted to the nature of the output\n", + " device. This option disables long format output.\n", + "\n", + " −\b−F\bF Do not follow symbolic links named as operands unless the −\b−H\bH\n", + " or −\b−L\bL options are specified. Write a ('\b'/\b/'\b') immedi‐\n", + " ately after each pathname that is a directory, an \n", + " ('\b'*\b*'\b') after each that is executable, a ('\b'|\b|'\b')\n", + " after each that is a FIFO, and an at-sign ('\b'@\b@'\b') after each\n", + " that is a symbolic link. For other file types, other symbols\n", + " may be written.\n", + "\n", + " −\b−H\bH Evaluate the file information and file type for symbolic\n", + " links specified on the command line to be those of the file\n", + " referenced by the link, and not the link itself; however, _\bl_\bs\n", + " shall write the name of the link itself and not the file ref‐\n", + " erenced by the link.\n", + "\n", + " −\b−L\bL Evaluate the file information and file type for all symbolic\n", + " links (whether named on the command line or encountered in a\n", + " file hierarchy) to be those of the file referenced by the\n", + " link, and not the link itself; however, _\bl_\bs shall write the\n", + " name of the link itself and not the file referenced by the\n", + " link. When −\b−L\bL is used with −\b−l\bl, write the contents of symbolic\n", + " links in the long format (see the STDOUT section).\n", + "\n", + " −\b−R\bR Recursively list subdirectories encountered. When a symbolic\n", + " link to a directory is encountered, the directory shall not\n", + " be recursively listed unless the −\b−L\bL option is specified. The\n", + " use of −\b−R\bR with −\b−d\bd or −\b−f\bf produces unspecified results.\n", + "\n", + " −\b−S\bS Sort with the primary key being file size (in decreasing\n", + " order) and the secondary key being filename in the collating\n", + " sequence (in increasing order).\n", + "\n", + " −\b−a\ba Write out all directory entries, including those whose names\n", + " begin with a ('\b'.\b.'\b').\n", + "\n", + " −\b−c\bc Use time of last modification of the file status information\n", + " (see the Base Definitions volume of POSIX.1‐2008,\n", + " <\b\b>) instead of last modification of the file itself\n", + " for sorting (−\b−t\bt) or writing (−\b−l\bl).\n", + "\n", + " −\b−d\bd Do not follow symbolic links named as operands unless the −\b−H\bH\n", + " or −\b−L\bL options are specified. Do not treat directories differ‐\n", + " ently than other types of files. The use of −\b−d\bd with −\b−R\bR or −\b−f\bf\n", + " produces unspecified results.\n", + "\n", + " −\b−f\bf List the entries in directory operands in the order they\n", + " appear in the directory. The behavior for non-directory oper‐\n", + " ands is unspecified. This option shall turn on −\b−a\ba. When −\b−f\bf\n", + " is specified, any occurrences of the −\b−r\br, −\b−S\bS, and −\b−t\bt options\n", + " shall be ignored and any occurrences of the −\b−A\bA, −\b−g\bg, −\b−l\bl, −\b−n\bn,\n", + " −\b−o\bo, and −\b−s\bs options may be ignored. The use of −\b−f\bf with −\b−R\bR or\n", + " −\b−d\bd produces unspecified results.\n", + "\n", + " −\b−g\bg Turn on the −\b−l\bl (ell) option, but disable writing the file's\n", + " owner name or number. Disable the −\b−C\bC, −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−i\bi For each file, write the file's file serial number (see\n", + " _\bs_\bt_\ba_\bt() in the System Interfaces volume of POSIX.1‐2008).\n", + "\n", + " −\b−k\bk Set the block size for the −\b−s\bs option and the per-directory\n", + " block count written for the −\b−l\bl, −\b−n\bn, −\b−s\bs, −\b−g\bg, and −\b−o\bo options\n", + " (see the STDOUT section) to 1024 bytes.\n", + "\n", + " −\b−l\bl (The letter ell.) Do not follow symbolic links named as oper‐\n", + " ands unless the −\b−H\bH or −\b−L\bL options are specified. Write out in\n", + " long format (see the STDOUT section). Disable the −\b−C\bC, −\b−m\bm, and\n", + " −\b−x\bx options.\n", + "\n", + " −\b−m\bm Stream output format; list pathnames across the page, sepa‐\n", + " rated by a character followed by a character.\n", + " Use a character as the list terminator and after\n", + " the separator sequence when there is not room on a line for\n", + " the next list entry. This option disables long format output.\n", + "\n", + " −\b−n\bn Turn on the −\b−l\bl (ell) option, but when writing the file's\n", + " owner or group, write the file's numeric UID or GID rather\n", + " than the user or group name, respectively. Disable the −\b−C\bC,\n", + " −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−o\bo Turn on the −\b−l\bl (ell) option, but disable writing the file's\n", + " group name or number. Disable the −\b−C\bC, −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−p\bp Write a ('\b'/\b/'\b') after each filename if that file is a\n", + " directory.\n", + "\n", + " −\b−q\bq Force each instance of non-printable filename characters and\n", + " characters to be written as the ('\b'?\b?'\b')\n", + " character. Implementations may provide this option by default\n", + " if the output is to a terminal device.\n", + "\n", + " −\b−r\br Reverse the order of the sort to get reverse collating\n", + " sequence oldest first, or smallest file size first depending\n", + " on the other options given.\n", + "\n", + " −\b−s\bs Indicate the total number of file system blocks consumed by\n", + " each file displayed. If the −\b−k\bk option is also specified, the\n", + " block size shall be 1024 bytes; otherwise, the block size is\n", + " implementation-defined.\n", + "\n", + " −\b−t\bt Sort with the primary key being time modified (most recently\n", + " modified first) and the secondary key being filename in the\n", + " collating sequence. For a symbolic link, the time used as\n", + " the sort key is that of the symbolic link itself, unless _\bl_\bs\n", + " is evaluating its file information to be that of the file\n", + " referenced by the link (see the −\b−H\bH and −\b−L\bL options).\n", + "\n", + " −\b−u\bu Use time of last access (see the Base Definitions volume of\n", + " POSIX.1‐2008, <\b\b>) instead of last modification of\n", + " the file for sorting (−\b−t\bt) or writing (−\b−l\bl).\n", + "\n", + " −\b−x\bx The same as −\b−C\bC, except that the multi-text-column output is\n", + " produced with entries sorted across, rather than down, the\n", + " columns. This option disables long format output.\n", + "\n", + " −\b−1\b1 (The numeric digit one.) Force output to be one entry per\n", + " line. This option does not disable long format output. (Long\n", + " format output is enabled by −\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo; and\n", + " disabled by −\b−C\bC, −\b−m\bm, and −\b−x\bx.)\n", + "\n", + " If an option that enables long format output (−\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo\n", + " is given with an option that disables long format output (−\b−C\bC, −\b−m\bm, and\n", + " −\b−x\bx), this shall not be considered an error. The last of these options\n", + " specified shall determine whether long format output is written.\n", + "\n", + " If −\b−R\bR, −\b−d\bd, or −\b−f\bf are specified, the results of specifying these mutu‐\n", + " ally-exclusive options are specified by the descriptions of these\n", + " options above. If more than one of any of the other options shown in\n", + " the SYNOPSIS section in mutually-exclusive sets are given, this shall\n", + " not be considered an error; the last option specified in each set shall\n", + " determine the output.\n", + "\n", + " Note that if −\b−t\bt is specified, −\b−c\bc and −\b−u\bu are not only mutually-exclusive\n", + " with each other, they are also mutually-exclusive with −\b−S\bS when deter‐\n", + " mining sort order. But even if −\b−S\bS is specified after all occurrences of\n", + " −\b−c\bc, −\b−t\bt, and −\b−u\bu, the last use of −\b−c\bc or −\b−u\bu determines the timestamp\n", + " printed when producing long format output.\n", + "\n", + "O\bOP\bPE\bER\bRA\bAN\bND\bDS\bS\n", + " The following operand shall be supported:\n", + "\n", + " _\bf_\bi_\bl_\be A pathname of a file to be written. If the file specified is\n", + " not found, a diagnostic message shall be output on standard\n", + " error.\n", + "\n", + "S\bST\bTD\bDI\bIN\bN\n", + " Not used.\n", + "\n", + "I\bIN\bNP\bPU\bUT\bT F\bFI\bIL\bLE\bES\bS\n", + " None.\n", + "\n", + "E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT V\bVA\bAR\bRI\bIA\bAB\bBL\bLE\bES\bS\n", + " The following environment variables shall affect the execution of _\bl_\bs:\n", + "\n", + " _\bC_\bO_\bL_\bU_\bM_\bN_\bS Determine the user's preferred column position width for\n", + " writing multiple text-column output. If this variable con‐\n", + " tains a string representing a decimal integer, the _\bl_\bs utility\n", + " shall calculate how many pathname text columns to write (see\n", + " −\b−C\bC) based on the width provided. If _\bC_\bO_\bL_\bU_\bM_\bN_\bS is not set or\n", + " invalid, an implementation-defined number of column positions\n", + " shall be assumed, based on the implementation's knowledge of\n", + " the output device. The column width chosen to write the names\n", + " of files in any given directory shall be constant. Filenames\n", + " shall not be truncated to fit into the multiple text-column\n", + " output.\n", + "\n", + " _\bL_\bA_\bN_\bG Provide a default value for the internationalization vari‐\n", + " ables that are unset or null. (See the Base Definitions vol‐\n", + " ume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b8_\b._\b2, _\bI_\bn_\bt_\be_\br_\bn_\ba_\bt_\bi_\bo_\bn_\ba_\bl_\bi_\bz_\ba_\bt_\bi_\bo_\bn _\bV_\ba_\br_\bi_\b‐\n", + " _\ba_\bb_\bl_\be_\bs for the precedence of internationalization variables\n", + " used to determine the values of locale categories.)\n", + "\n", + " _\bL_\bC_\b__\bA_\bL_\bL If set to a non-empty string value, override the values of\n", + " all the other internationalization variables.\n", + "\n", + " _\bL_\bC_\b__\bC_\bO_\bL_\bL_\bA_\bT_\bE\n", + " Determine the locale for character collation information in\n", + " determining the pathname collation sequence.\n", + "\n", + " _\bL_\bC_\b__\bC_\bT_\bY_\bP_\bE Determine the locale for the interpretation of sequences of\n", + " bytes of text data as characters (for example, single-byte as\n", + " opposed to multi-byte characters in arguments) and which\n", + " characters are defined as printable (character class p\bpr\bri\bin\bnt\bt).\n", + "\n", + " _\bL_\bC_\b__\bM_\bE_\bS_\bS_\bA_\bG_\bE_\bS\n", + " Determine the locale that should be used to affect the format\n", + " and contents of diagnostic messages written to standard\n", + " error.\n", + "\n", + " _\bL_\bC_\b__\bT_\bI_\bM_\bE Determine the format and contents for date and time strings\n", + " written by _\bl_\bs.\n", + "\n", + " _\bN_\bL_\bS_\bP_\bA_\bT_\bH Determine the location of message catalogs for the processing\n", + " of _\bL_\bC_\b__\bM_\bE_\bS_\bS_\bA_\bG_\bE_\bS.\n", + "\n", + " _\bT_\bZ Determine the timezone for date and time strings written by\n", + " _\bl_\bs. If _\bT_\bZ is unset or null, an unspecified default timezone\n", + " shall be used.\n", + "\n", + "A\bAS\bSY\bYN\bNC\bCH\bHR\bRO\bON\bNO\bOU\bUS\bS E\bEV\bVE\bEN\bNT\bTS\bS\n", + " Default.\n", + "\n", + "S\bST\bTD\bDO\bOU\bUT\bT\n", + " The default format shall be to list one entry per line to standard out‐\n", + " put; the exceptions are to terminals or when one of the −\b−C\bC, −\b−m\bm, or −\b−x\bx\n", + " options is specified. If the output is to a terminal, the format is\n", + " implementation-defined.\n", + "\n", + " When −\b−m\bm is specified, the format used for the last element of the list\n", + " shall be:\n", + "\n", + " \"\b\"%\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be_\bn_\ba_\bm_\be>\n", + "\n", + " The format used for each other element of the list shall be:\n", + "\n", + " \"\b\"%\b%s\bs,\b,%\b%s\bs\"\b\",\b, <\b<_\bf_\bi_\bl_\be_\bn_\ba_\bm_\be>, <_\bs_\be_\bp_\ba_\br_\ba_\bt_\bo_\br>\n", + "\n", + " where, if there is not room for the next element of the list to fit\n", + " within the current line length, <_\bs_\be_\bp_\ba_\br_\ba_\bt_\bo_\br> is a string containing an\n", + " optional character and a mandatory character; other‐\n", + " wise it is a single character.\n", + "\n", + " If the −\b−i\bi option is specified, the file's file serial number (see the\n", + " Base Definitions volume of POSIX.1‐2008, <\b\b>) shall be written\n", + " in the following format before any other output for the corresponding\n", + " entry:\n", + "\n", + " %\b%u\bu \"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bs_\be_\br_\bi_\ba_\bl _\bn_\bu_\bm_\bb_\be_\br>\n", + "\n", + " If the −\b−l\bl option is specified, the following information shall be writ‐\n", + " ten for files other than character special and block special files:\n", + "\n", + " \"\b\"%\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bm_\bo_\bd_\be>, <_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bl_\bi_\bn_\bk_\bs>,\n", + " <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be>, <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be>, <_\bs_\bi_\bz_\be>, <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be>,\n", + " <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be>\n", + "\n", + " If the −\b−l\bl option is specified, the following information shall be writ‐\n", + " ten for character special and block special files:\n", + "\n", + " \"\b\"%\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs %\b%s\bs %\b%s\bs %\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bm_\bo_\bd_\be>, <_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bl_\bi_\bn_\bk_\bs>,\n", + " <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be>, <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be>, <_\bd_\be_\bv_\bi_\bc_\be _\bi_\bn_\bf_\bo>, <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be>,\n", + " <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be>\n", + "\n", + " In both cases if the file is a symbolic link and the −\b−L\bL option is also\n", + " specified, this information shall be for the file resolved from the\n", + " symbolic link, except that the <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be> field shall contain the path‐\n", + " name of the symbolic link itself. If the file is a symbolic link and\n", + " the −\b−L\bL option is not specified, this information shall be about the\n", + " link itself and the <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be> field shall be of the form:\n", + "\n", + " \"\b\"%\b%s\bs −\b−>\b> %\b%s\bs\"\b\",\b, <\b<_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be _\bo_\bf _\bl_\bi_\bn_\bk>, <_\bc_\bo_\bn_\bt_\be_\bn_\bt_\bs _\bo_\bf _\bl_\bi_\bn_\bk>\n", + "\n", + " The −\b−n\bn, −\b−g\bg, and −\b−o\bo options use the same format as −\b−l\bl, but with omitted\n", + " items and their associated characters. See the OPTIONS section.\n", + "\n", + " In both the preceding −\b−l\bl forms, if <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be> or <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be> cannot\n", + " be determined, or if −\b−n\bn is given, they shall be replaced with their\n", + " associated numeric values using the format %\b%u\bu.\n", + "\n", + " The <_\bs_\bi_\bz_\be> field shall contain the value that would be returned for the\n", + " file in the _\bs_\bt_\b__\bs_\bi_\bz_\be field of s\bst\btr\bru\buc\bct\bt s\bst\bta\bat\bt (see the Base Definitions vol‐\n", + " ume of POSIX.1‐2008, <\b\b>). Note that for some file types this\n", + " value is unspecified.\n", + "\n", + " The <_\bd_\be_\bv_\bi_\bc_\be _\bi_\bn_\bf_\bo> field shall contain implementation-defined informa‐\n", + " tion associated with the device in question.\n", + "\n", + " The <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be> field shall contain the appropriate date and time‐\n", + " stamp of when the file was last modified. In the POSIX locale, the\n", + " field shall be the equivalent of the output of the following _\bd_\ba_\bt_\be com‐\n", + " mand:\n", + "\n", + " d\bda\bat\bte\be \"\b\"+\b+%\b%b\bb %\b%e\be %\b%H\bH:\b:%\b%M\bM\"\b\"\n", + "\n", + " if the file has been modified in the last six months, or:\n", + "\n", + " d\bda\bat\bte\be \"\b\"+\b+%\b%b\bb %\b%e\be %\b%Y\bY\"\b\"\n", + "\n", + " (where two characters are used between %\b%e\be and %\b%Y\bY) if the file\n", + " has not been modified in the last six months or if the modification\n", + " date is in the future, except that, in both cases, the final \n", + " produced by _\bd_\ba_\bt_\be shall not be included and the output shall be as if\n", + " the _\bd_\ba_\bt_\be command were executed at the time of the last modification\n", + " date of the file rather than the current time. When the _\bL_\bC_\b__\bT_\bI_\bM_\bE locale\n", + " category is not set to the POSIX locale, a different format and order\n", + " of presentation of this field may be used.\n", + "\n", + " If the pathname was specified as a _\bf_\bi_\bl_\be operand, it shall be written as\n", + " specified.\n", + "\n", + " The file mode written under the −\b−l\bl, −\b−n\bn, −\b−g\bg, and −\b−o\bo options shall con‐\n", + " sist of the following format:\n", + "\n", + " \"\b\"%\b%c\bc%\b%s\bs%\b%s\bs%\b%s\bs%\b%s\bs\"\b\",\b, <\b<_\be_\bn_\bt_\br_\by _\bt_\by_\bp_\be>, <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>,\n", + " <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>,\n", + " <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg>\n", + "\n", + " The <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg> shall be the empty string\n", + " if there is no alternate or additional access control method associated\n", + " with the file; otherwise, it shall be a string containing a single\n", + " printable character that is not a .\n", + "\n", + " The <_\be_\bn_\bt_\br_\by _\bt_\by_\bp_\be> character shall describe the type of file, as follows:\n", + "\n", + " d Directory.\n", + "\n", + " b Block special file.\n", + "\n", + " c Character special file.\n", + "\n", + " l (ell) Symbolic link.\n", + "\n", + " p FIFO.\n", + "\n", + " − Regular file.\n", + "\n", + " Implementations may add other characters to this list to represent\n", + " other implementation-defined file types.\n", + "\n", + " The next three fields shall be three characters each:\n", + "\n", + " <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file owner class (see the Base Definitions\n", + " volume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b4_\b._\b4, _\bF_\bi_\bl_\be _\bA_\bc_\bc_\be_\bs_\bs _\bP_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs).\n", + "\n", + " <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file group class.\n", + "\n", + " <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file other class.\n", + "\n", + " Each field shall have three character positions:\n", + "\n", + " 1. If '\b'r\br'\b', the file is readable; if '\b'−\b−'\b', the file is not readable.\n", + "\n", + " 2. If '\b'w\bw'\b', the file is writable; if '\b'−\b−'\b', the file is not writable.\n", + "\n", + " 3. The first of the following that applies:\n", + "\n", + " S If in <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is not executable and\n", + " set-user-ID mode is set. If in <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file\n", + " is not executable and set-group-ID mode is set.\n", + "\n", + " s If in <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is executable and set-\n", + " user-ID mode is set. If in <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is\n", + " executable and set-group-ID mode is set.\n", + "\n", + " T If in <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs> and the file is a directory, search\n", + " permission is not granted to others, and the restricted dele‐\n", + " tion flag is set.\n", + "\n", + " t If in <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs> and the file is a directory, search\n", + " permission is granted to others, and the restricted deletion\n", + " flag is set.\n", + "\n", + " x The file is executable or the directory is searchable.\n", + "\n", + " − None of the attributes of '\b'S\bS'\b', '\b's\bs'\b', '\b'T\bT'\b', '\b't\bt'\b', or '\b'x\bx'\b' applies.\n", + "\n", + " Implementations may add other characters to this list for the third\n", + " character position. Such additions shall, however, be written in\n", + " lowercase if the file is executable or searchable, and in uppercase\n", + " if it is not.\n", + "\n", + " If any of the −\b−l\bl, −\b−n\bn, −\b−s\bs, −\b−g\bg, or −\b−o\bo options is specified, each list of\n", + " files within the directory shall be preceded by a status line indicat‐\n", + " ing the number of file system blocks occupied by files in the directory\n", + " in 512-byte units if the −\b−k\bk option is not specified, or 1024-byte units\n", + " if the −\b−k\bk option is specified, rounded up to the next integral number\n", + " of units, if necessary. In the POSIX locale, the format shall be:\n", + "\n", + " \"\b\"t\bto\bot\bta\bal\bl %\b%u\bu\\\b\\n\bn\"\b\",\b, <\b<_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bu_\bn_\bi_\bt_\bs _\bi_\bn _\bt_\bh_\be _\bd_\bi_\br_\be_\bc_\bt_\bo_\br_\by>\n", + "\n", + " If more than one directory, or a combination of non-directory files and\n", + " directories are written, either as a result of specifying multiple op‐\n", + " erands, or the −\b−R\bR option, each list of files within a directory shall\n", + " be preceded by:\n", + "\n", + " \"\b\"\\\b\\n\bn%\b%s\bs:\b:\\\b\\n\bn\"\b\",\b, <\b<_\bd_\bi_\br_\be_\bc_\bt_\bo_\br_\by _\bn_\ba_\bm_\be>\n", + "\n", + " If this string is the first thing to be written, the first \n", + " shall not be written. This output shall precede the number of units in\n", + " the directory.\n", + "\n", + " If the −\b−s\bs option is given, each file shall be written with the number\n", + " of blocks used by the file. Along with −\b−C\bC, −\b−1\b1, −\b−m\bm, or −\b−x\bx, the number\n", + " and a shall precede the filename; with −\b−l\bl, −\b−n\bn, −\b−g\bg, or −\b−o\bo, they\n", + " shall precede each line describing a file.\n", + "\n", + "S\bST\bTD\bDE\bER\bRR\bR\n", + " The standard error shall be used only for diagnostic messages.\n", + "\n", + "O\bOU\bUT\bTP\bPU\bUT\bT F\bFI\bIL\bLE\bES\bS\n", + " None.\n", + "\n", + "E\bEX\bXT\bTE\bEN\bND\bDE\bED\bD D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\n", + " None.\n", + "\n", + "E\bEX\bXI\bIT\bT S\bST\bTA\bAT\bTU\bUS\bS\n", + " The following exit values shall be returned:\n", + "\n", + " 0 Successful completion.\n", + "\n", + " >0 An error occurred.\n", + "\n", + "C\bCO\bON\bNS\bSE\bEQ\bQU\bUE\bEN\bNC\bCE\bES\bS O\bOF\bF E\bER\bRR\bRO\bOR\bRS\bS\n", + " Default.\n", + "\n", + " _\bT_\bh_\be _\bf_\bo_\bl_\bl_\bo_\bw_\bi_\bn_\bg _\bs_\be_\bc_\bt_\bi_\bo_\bn_\bs _\ba_\br_\be _\bi_\bn_\bf_\bo_\br_\bm_\ba_\bt_\bi_\bv_\be_\b.\n", + "\n", + "A\bAP\bPP\bPL\bLI\bIC\bCA\bAT\bTI\bIO\bON\bN U\bUS\bSA\bAG\bGE\bE\n", + " Many implementations use the ('\b'=\b='\b') to denote sockets\n", + " bound to the file system for the −\b−F\bF option. Similarly, many historical\n", + " implementations use the '\b's\bs'\b' character to denote sockets as the entry\n", + " type characters for the −\b−l\bl option.\n", + "\n", + " It is difficult for an application to use every part of the file modes\n", + " field of _\bl_\bs −\b−l\bl in a portable manner. Certain file types and executable\n", + " bits are not guaranteed to be exactly as shown, as implementations may\n", + " have extensions. Applications can use this field to pass directly to a\n", + " user printout or prompt, but actions based on its contents should gen‐\n", + " erally be deferred, instead, to the _\bt_\be_\bs_\bt utility.\n", + "\n", + " The output of _\bl_\bs (with the −\b−l\bl and related options) contains information\n", + " that logically could be used by utilities such as _\bc_\bh_\bm_\bo_\bd and _\bt_\bo_\bu_\bc_\bh to\n", + " restore files to a known state. However, this information is presented\n", + " in a format that cannot be used directly by those utilities or be eas‐\n", + " ily translated into a format that can be used. A character has been\n", + " added to the end of the permissions string so that applications at\n", + " least have an indication that they may be working in an area they do\n", + " not understand instead of assuming that they can translate the permis‐\n", + " sions string into something that can be used. Future versions or\n", + " related documents may define one or more specific characters to be used\n", + " based on different standard additional or alternative access control\n", + " mechanisms.\n", + "\n", + " As with many of the utilities that deal with filenames, the output of\n", + " _\bl_\bs for multiple files or in one of the long listing formats must be\n", + " used carefully on systems where filenames can contain embedded white\n", + " space. Systems and system administrators should institute policies and\n", + " user training to limit the use of such filenames.\n", + "\n", + " The number of disk blocks occupied by the file that it reports varies\n", + " depending on underlying file system type, block size units reported,\n", + " and the method of calculating the number of blocks. On some file system\n", + " types, the number is the actual number of blocks occupied by the file\n", + " (counting indirect blocks and ignoring holes in the file); on others it\n", + " is calculated based on the file size (usually making an allowance for\n", + " indirect blocks, but ignoring holes).\n", + "\n", + "E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS\n", + " An example of a small directory tree being fully listed with _\bl_\bs −\b−l\bla\baR\bRF\bF a\ba\n", + " in the POSIX locale:\n", + "\n", + " t\bto\bot\bta\bal\bl 1\b11\b1\n", + " d\bdr\brw\bwx\bxr\br-\b-x\bxr\br-\b-x\bx 3\b3 f\bfo\box\bx p\bpr\bro\bog\bg 6\b64\b4 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 .\b./\b/\n", + " d\bdr\brw\bwx\bxr\brw\bwx\bxr\brw\bwx\bx 4\b4 f\bfo\box\bx p\bpr\bro\bog\bg 3\b32\b26\b64\b4 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b09\b9 .\b..\b./\b/\n", + " d\bdr\brw\bwx\bxr\br-\b-x\bxr\br-\b-x\bx 2\b2 f\bfo\box\bx p\bpr\bro\bog\bg 4\b48\b8 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 b\bb/\b/\n", + " -\b-r\brw\bwx\bxr\br-\b--\b-r\br-\b--\b- 1\b1 f\bfo\box\bx p\bpr\bro\bog\bg 5\b57\b72\b2 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 f\bfo\boo\bo*\b*\n", + "\n", + " a/b:\n", + " total 4\n", + " drwxr-xr-x 2 fox prog 48 Jul 4 12:07 ./\n", + " drwxr-xr-x 3 fox prog 64 Jul 4 12:07 ../\n", + " -rw-r--r-- 1 fox prog 700 Jul 4 12:07 bar\n", + "\n", + "R\bRA\bAT\bTI\bIO\bON\bNA\bAL\bLE\bE\n", + " Some historical implementations of the _\bl_\bs utility show all entries in a\n", + " directory except dot and dot-dot when a superuser invokes _\bl_\bs without\n", + " specifying the −\b−a\ba option. When ``normal'' users invoke _\bl_\bs without spec‐\n", + " ifying −\b−a\ba, they should not see information about any files with names\n", + " beginning with a unless they were named as _\bf_\bi_\bl_\be operands.\n", + "\n", + " Implementations are expected to traverse arbitrary depths when process‐\n", + " ing the −\b−R\bR option. The only limitation on depth should be based on run‐\n", + " ning out of physical storage for keeping track of untraversed directo‐\n", + " ries.\n", + "\n", + " The −\b−1\b1 (one) option was historically found in BSD and BSD-derived\n", + " implementations only. It is required in this volume of POSIX.1‐2008 so\n", + " that conforming applications might ensure that output is one entry per\n", + " line, even if the output is to a terminal.\n", + "\n", + " The −\b−S\bS option was added in Issue 7, but had been provided by several\n", + " implementations for many years. The description given in the standard\n", + " documents historic practice, but does not match much of the documenta‐\n", + " tion that described its behavior. Historical documentation typically\n", + " described it as something like:\n", + "\n", + " −\b−S\bS Sort by size (largest size first) instead of by name. Special\n", + " character devices (listed last) are sorted by name.\n", + "\n", + " even though the file type was never considered when sorting the output.\n", + " Character special files do typically sort close to the end of the list\n", + " because their file size on most implementations is zero. But they are\n", + " sorted alphabetically with any other files that happen to have the same\n", + " file size (zero), not sorted separately and added to the end.\n", + "\n", + " This volume of POSIX.1‐2008 is frequently silent about what happens\n", + " when mutually-exclusive options are specified. Except for −\b−R\bR, −\b−d\bd, and\n", + " −\b−f\bf, the _\bl_\bs utility is required to accept multiple options from each\n", + " mutually-exclusive option set without treating them as errors and to\n", + " use the behavior specified by the last option given in each mutually-\n", + " exclusive set. Since _\bl_\bs is one of the most aliased commands, it is\n", + " important that the implementation perform intuitively. For example, if\n", + " the alias were:\n", + "\n", + " a\bal\bli\bia\bas\bs l\bls\bs=\b=\"\b\"l\bls\bs −\b−C\bC\"\b\"\n", + "\n", + " and the user typed _\bl_\bs −\b−1\b1 (one), single-text-column output should\n", + " result, not an error.\n", + "\n", + " The −\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo options are not mutually-exclusive\n", + " options. They all enable long format output. They work together to\n", + " determine whether the file's owner is written (no if −\b−g\bg is present),\n", + " file's group is written (no if −\b−o\bo is present), and if the file's group\n", + " or owner is written whether it is written as the name (default) or a\n", + " string representation of the UID or GID number (if −\b−n\bn is present). The\n", + " −\b−C\bC, −\b−m\bm, −\b−x\bx, and −\b−1\b1 (one) are mutually-exclusive options and the first\n", + " three of these disable long format output. The −\b−1\b1 (one) option does not\n", + " directly change whether or not long format output is enabled, but by\n", + " overriding −\b−C\bC, −\b−m\bm, and −\b−x\bx, it can re-enable long format output that had\n", + " been disabled by one of these options.\n", + "\n", + " Earlier versions of this standard did not describe the BSD −\b−A\bA option\n", + " (like −\b−a\ba, but dot and dot-dot are not written out). It has been added\n", + " due to widespread implementation.\n", + "\n", + " Implementations may make −\b−q\bq the default for terminals to prevent trojan\n", + " horse attacks on terminals with special escape sequences. This is not\n", + " required because:\n", + "\n", + " * Some control characters may be useful on some terminals; for exam‐\n", + " ple, a system might write them as \"\b\"\\\b\\0\b00\b01\b1\"\b\" or \"\b\"^\b^A\bA\"\b\".\n", + "\n", + " * Special behavior for terminals is not relevant to applications\n", + " portability.\n", + "\n", + " An early proposal specified that the <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\b‐\n", + " _\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg> had to be '\b'+\b+'\b' if there was an alternate access\n", + " method used on the file or if there was not. This was changed\n", + " to be if there is not and a single printable character if there\n", + " is. This was done for three reasons:\n", + "\n", + " 1. There are historical implementations using characters other than\n", + " '\b'+\b+'\b'.\n", + "\n", + " 2. There are implementations that vary this character used in that\n", + " position to distinguish between various alternate access methods in\n", + " use.\n", + "\n", + " 3. The standard developers did not want to preclude future specifica‐\n", + " tions that might need a way to specify more than one alternate\n", + " access method.\n", + "\n", + " Nonetheless, implementations providing a single alternate access method\n", + " are encouraged to use '\b'+\b+'\b'.\n", + "\n", + " Earlier versions of this standard did not have the −\b−k\bk option, which\n", + " meant that the −\b−s\bs option could not be used portably as its block size\n", + " was implementation-defined, and the units used to specify the number of\n", + " blocks occupied by files in a directory in an _\bl_\bs −\b−l\bl listing were fixed\n", + " as 512-byte units. The −\b−k\bk option has been added to provide a way for\n", + " the −\b−s\bs option to be used portably, and for consistency it also changes\n", + " the aforementioned units from 512-byte to 1024-byte.\n", + "\n", + " The <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be> field in the −\b−l\bl format is specified only for the\n", + " POSIX locale. As noted, the format can be different in other locales.\n", + " No mechanism for defining this is present in this volume of\n", + " POSIX.1‐2008, as the appropriate vehicle is a messaging system; that\n", + " is, the format should be specified as a ``message''.\n", + "\n", + "F\bFU\bUT\bTU\bUR\bRE\bE D\bDI\bIR\bRE\bEC\bCT\bTI\bIO\bON\bNS\bS\n", + " Allowing −\b−f\bf to ignore the −\b−A\bA, −\b−g\bg, −\b−l\bl, −\b−n\bn, −\b−o\bo, and −\b−s\bs options may be\n", + " removed in a future version.\n", + "\n", + "S\bSE\bEE\bE A\bAL\bLS\bSO\bO\n", + " _\bc_\bh_\bm_\bo_\bd, _\bf_\bi_\bn_\bd\n", + "\n", + " The Base Definitions volume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b4_\b._\b4, _\bF_\bi_\bl_\be _\bA_\bc_\bc_\be_\bs_\bs\n", + " _\bP_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs, _\bC_\bh_\ba_\bp_\bt_\be_\br _\b8, _\bE_\bn_\bv_\bi_\br_\bo_\bn_\bm_\be_\bn_\bt _\bV_\ba_\br_\bi_\ba_\bb_\bl_\be_\bs, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b1_\b2_\b._\b2, _\bU_\bt_\bi_\bl_\bi_\bt_\by\n", + " _\bS_\by_\bn_\bt_\ba_\bx _\bG_\bu_\bi_\bd_\be_\bl_\bi_\bn_\be_\bs, <\b\b>\n", + "\n", + " The System Interfaces volume of POSIX.1‐2008, _\bf_\bs_\bt_\ba_\bt_\ba_\bt()\n", + "\n", + "C\bCO\bOP\bPY\bYR\bRI\bIG\bGH\bHT\bT\n", + " Portions of this text are reprinted and reproduced in electronic form\n", + " from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology\n", + " -- Portable Operating System Interface (POSIX), The Open Group Base\n", + " Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐\n", + " cal and Electronics Engineers, Inc and The Open Group. (This is\n", + " POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the\n", + " event of any discrepancy between this version and the original IEEE and\n", + " The Open Group Standard, the original IEEE and The Open Group Standard\n", + " is the referee document. The original Standard can be obtained online\n", + " at http://www.unix.org/online.html .\n", + "\n", + " Any typographical or formatting errors that appear in this page are\n", + " most likely to have been introduced during the conversion of the source\n", + " files to man page format. To report such errors, see https://www.ker‐\n", + " nel.org/doc/man-pages/reporting_bugs.html .\n", + "\n", + "IEEE/The Open Group 2013 LS(1POSIX)\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# q\n", + "bash: q: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo Hello World\n", + "Hello World\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# path\n", + "bash: path: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# PATH\n", + "bash: PATH: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo $PATH\n", + "/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo $SHELL\n", + "/bin/bash\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YoEgruUhqvzw", + "colab_type": "text" + }, + "source": [ + "## Navigating Directories\n", + "\n", + "You can change your current directory using the \"cd\" shell command. Note that \"cd\" is not a Unix program. Once in a directory, you can use the \"ls\" command to list the contents or \"pwd\" to remind yourself your current working directory. You can move back one level in your current directory hierarchy using \"cd ..\". In general \"..\" represents the path to a directory one level above your current directory, \"../..\" represents two levels up, and so on. \".\" represents the current directory. If you look at the PATH environment variable, you'll notice that the last item is \".\", telling the shell to look into your current directory for commands. Finally the \"~\" character always refers to your home directory.\n", + "\n", + "Some other file manipulation commands:\n", + "\n", + " - The \"mkdir\" command creates new directories. \n", + " - \"cp\" and \"mv\" allow you to copy and move (or rename) files, taking 2 arguments: the original path/filename and the target path/filename. \n", + " - The \"rm\" and \"rmdir\" commands remove (delete) files and directories.\n", + "\n", + "\n", + "*Exercise 2:* Using the \"cd\" command, navigate into \"drive/My\\ Drive\" directory. Create a new directory called \"Data-1441\", and another directory inside \"Data-1441\" called \"Lab-1-Solutions\". Perform the rest of the lab in this directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "A16VzZ3G0J8x", + "colab_type": "code", + "outputId": "c931496a-f7ba-4df7-f530-d79f6ec9f679", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 272 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# pwd\n", + "/content\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# drive/My\\Drive\n", + "bash: drive/MyDrive: No such file or directory\n", + "\u001b]0;root@47551fbb9a44: /content/drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd My\\ Drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# pwd\n", + "/content/drive/My Drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# mkdir Data-1401\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1401\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive/Data-1401\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1401\u001b[00m# mkdir Lab-1-Solutions\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive/Data-1401\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1401\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o38c4lbsqvzy", + "colab_type": "text" + }, + "source": [ + "## Exploring Unix Filesystem\n", + "\n", + "You can look at the root directory of the system by issuing \"ls /\". As explained in lecture, Unix uses the file system to communicate with devices and between processes. \"/etc\" keeps the configuration files of the system. \"/bin\" and \"/sbin\" store most of the standard Unix programs. \"/usr\" stores installes programs and their associate files, with \"/usr/bin\" usually storing the commands you can run. \n", + "\n", + "*Exercise 3:* List the \"/dev\" directory. How many SSD storage devices do you see? How many partitions does each device have? (Answer in box below)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yNj2LXzP2ksl", + "colab_type": "code", + "outputId": "c96151ba-85c9-4f7b-e793-3aae6d124a94", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /dev\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@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd /dev\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# pwd\n", + "/dev\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# df --help\n", + "Usage: df [OPTION]... [FILE]...\n", + "Show information about the file system on which each FILE resides,\n", + "or all file systems by default.\n", + "\n", + "Mandatory arguments to long options are mandatory for short options too.\n", + " -a, --all include pseudo, duplicate, inaccessible file systems\n", + " -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\n", + " '-BM' prints sizes in units of 1,048,576 bytes;\n", + " see SIZE format below\n", + " -h, --human-readable print sizes in powers of 1024 (e.g., 1023M)\n", + " -H, --si print sizes in powers of 1000 (e.g., 1.1G)\n", + " -i, --inodes list inode information instead of block usage\n", + " -k like --block-size=1K\n", + " -l, --local limit listing to local file systems\n", + " --no-sync do not invoke sync before getting usage info (default)\n", + " --output[=FIELD_LIST] use the output format defined by FIELD_LIST,\n", + " or print all fields if FIELD_LIST is omitted.\n", + " -P, --portability use the POSIX output format\n", + " --sync invoke sync before getting usage info\n", + " --total elide all entries insignificant to available space,\n", + " and produce a grand total\n", + " -t, --type=TYPE limit listing to file systems of type TYPE\n", + " -T, --print-type print file system type\n", + " -x, --exclude-type=TYPE limit listing to file systems not of type TYPE\n", + " -v (ignored)\n", + " --help display this help and exit\n", + " --version output version information and exit\n", + "\n", + "Display values are in units of the first available SIZE from --block-size,\n", + "and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.\n", + "Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).\n", + "\n", + "The SIZE argument is an integer and optional unit (example: 10K is 10*1024).\n", + "Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).\n", + "\n", + "FIELD_LIST is a comma-separated list of columns to be included. Valid\n", + "field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',\n", + "'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).\n", + "\n", + "GNU coreutils online help: \n", + "Full documentation at: \n", + "or available locally via: info '(coreutils) df invocation'\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# df -H\n", + "Filesystem Size Used Avail Use% Mounted on\n", + "overlay 116G 31G 80G 28% /\n", + "tmpfs 68M 0 68M 0% /dev\n", + "tmpfs 6.9G 0 6.9G 0% /sys/fs/cgroup\n", + "tmpfs 6.9G 8.2k 6.9G 1% /var/colab\n", + "/dev/sda1 123G 33G 91G 27% /etc/hosts\n", + "shm 6.5G 4.1k 6.5G 1% /dev/shm\n", + "tmpfs 6.9G 0 6.9G 0% /proc/acpi\n", + "tmpfs 6.9G 0 6.9G 0% /proc/scsi\n", + "tmpfs 6.9G 0 6.9G 0% /sys/firmware\n", + "drive 17G 585M 16G 4% /content/drive\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# lsblk --help\n", + "\n", + "Usage:\n", + " lsblk [options] [ ...]\n", + "\n", + "List information about block devices.\n", + "\n", + "Options:\n", + " -a, --all print all devices\n", + " -b, --bytes print SIZE in bytes rather than in human readable format\n", + " -d, --nodeps don't print slaves or holders\n", + " -D, --discard print discard capabilities\n", + " -z, --zoned print zone model\n", + " -e, --exclude exclude devices by major number (default: RAM disks)\n", + " -f, --fs output info about filesystems\n", + " -i, --ascii use ascii characters only\n", + " -I, --include show only devices with specified major numbers\n", + " -J, --json use JSON output format\n", + " -l, --list use list format output\n", + " -T, --tree use tree format output\n", + " -m, --perms output info about permissions\n", + " -n, --noheadings don't print headings\n", + " -o, --output output columns\n", + " -O, --output-all output all columns\n", + " -p, --paths print complete device path\n", + " -P, --pairs use key=\"value\" output format\n", + " -r, --raw use raw output format\n", + " -s, --inverse inverse dependencies\n", + " -S, --scsi output info about SCSI devices\n", + " -t, --topology output info about topology\n", + " -x, --sort sort output by \n", + "\n", + " -h, --help display this help\n", + " -V, --version display version\n", + "\n", + "Available output columns:\n", + " NAME device name\n", + " KNAME internal kernel device name\n", + " MAJ:MIN major:minor device number\n", + " FSTYPE filesystem type\n", + " MOUNTPOINT where the device is mounted\n", + " LABEL filesystem LABEL\n", + " UUID filesystem UUID\n", + " PARTTYPE partition type UUID\n", + " PARTLABEL partition LABEL\n", + " PARTUUID partition UUID\n", + " PARTFLAGS partition flags\n", + " RA read-ahead of the device\n", + " RO read-only device\n", + " RM removable device\n", + " HOTPLUG removable or hotplug device (usb, pcmcia, ...)\n", + " MODEL device identifier\n", + " SERIAL disk serial number\n", + " SIZE size of the device\n", + " STATE state of the device\n", + " OWNER user name\n", + " GROUP group name\n", + " MODE device node permissions\n", + " ALIGNMENT alignment offset\n", + " MIN-IO minimum I/O size\n", + " OPT-IO optimal I/O size\n", + " PHY-SEC physical sector size\n", + " LOG-SEC logical sector size\n", + " ROTA rotational device\n", + " SCHED I/O scheduler name\n", + " RQ-SIZE request queue size\n", + " TYPE device type\n", + " DISC-ALN discard alignment offset\n", + " DISC-GRAN discard granularity\n", + " DISC-MAX discard max bytes\n", + " DISC-ZERO discard zeroes data\n", + " WSAME write same max bytes\n", + " WWN unique storage identifier\n", + " RAND adds randomness\n", + " PKNAME internal parent kernel device name\n", + " HCTL Host:Channel:Target:Lun for SCSI\n", + " TRAN device transport type\n", + " SUBSYSTEMS de-duplicated chain of subsystems\n", + " REV device revision\n", + " VENDOR device vendor\n", + " ZONED zone model\n", + "\n", + "For more details see lsblk(8).\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# lsblk\n", + "NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\n", + "loop0 7:0 0 110G 0 loop \n", + "sda 8:0 0 120G 0 disk \n", + "├─sda1 8:1 115.9G 0 part /etc/hosts\n", + "├─sda2 8:2 0 16M 0 part \n", + "├─sda3 8:3 0 2G 0 part \n", + "├─sda4 8:4 0 16M 0 part \n", + "├─sda5 8:5 0 2G 0 part \n", + "├─sda6 8:6 512B 0 part \n", + "├─sda7 8:7 0 512B 0 part \n", + "├─sda8 8:8 16M 0 part \n", + "├─sda9 8:9 0 512B 0 part \n", + "├─sda10 8:10 0 512B 0 part \n", + "├─sda11 8:11 8M 0 part \n", + "└─sda12 8:12 0 32M 0 part \n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7P9EG0KOqvz2", + "colab_type": "text" + }, + "source": [ + "## Text File Manipulation\n", + "\n", + "As explained in lecture, Unix stores most information in text files. For example, the list of all users and their home directories are stored in \"/etc/passwd\". Let get some familiarity with the most commonly used commands to manipulate files.\n", + "\n", + " - You can see the contents contents a file using the \"cat\" (concatenate) command. Try executing \"cat /etc/passwd\". You'll get a huge list that will go by your screen quickly. \n", + " \n", + " - To go through the file page by page, you can use the \"less\" or \"more\" commands. \n", + " \n", + " - You can see the first or last N (N=10 by default) lines of a file using \"head\" or \"tail\" commands. For example \"tail -20 /etc/passwd\" will list the last 20 lines. \n", + " \n", + " - You can search a test file using the \"grep\" command, which takes a string keyword as the first argument and a filename as the second, and by default prints out every line in the file that contrains the string. So for example you can do \"grep \\$USER /etc/passwd\" to find the line corresponding to your account. Some useful flags: \n", + " \n", + " - \"-i\" ignores the case of the keyword\n", + " - \"-v\" display those lines that do NOT match \n", + " - \"-n\" precede each matching line with the line number \n", + " - \"-c\" print only the total count of matched lines \n", + " \n", + " For example \"grep -c \\$USER /etc/passwd\" should show that you are in the password file just once. \n", + " \n", + " - The \"wc\" (word count) command counts the number of lines, words, and characters in a file. By default \"wc\" gives you all three numbers, but \"-w\", \"-l\", or \"-c\" flags \n", + "\n", + "*Exercise 4:* Count how many lines in the password file contain the letter \"w\". " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "UlsANMuf2qMs", + "colab_type": "code", + "outputId": "848dba2c-0729-4973-8c17-242783190c40", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# head -n\n", + "head: option requires an argument -- 'n'\n", + "Try 'head --help' for more information.\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# head -n 5 /etc/passwd\n", + "root:x:0:0:root:/root:/bin/bash\n", + "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n", + "bin:x:2:2:bin:/bin:/usr/sbin/nologin\n", + "sys:x:3:3:sys:/dev:/usr/sbin/nologin\n", + "sync:x:4:65534:sync:/bin:/bin/sync\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat /etc/passwd\n", + "root:x:0:0:root:/root:/bin/bash\n", + "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n", + "bin:x:2:2:bin:/bin:/usr/sbin/nologin\n", + "sys:x:3:3:sys:/dev:/usr/sbin/nologin\n", + "sync:x:4:65534:sync:/bin:/bin/sync\n", + "games:x:5:60:games:/usr/games:/usr/sbin/nologin\n", + "man:x:6:12:man:/var/cache/man:/usr/sbin/nologin\n", + "lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin\n", + "mail:x:8:8:mail:/var/mail:/usr/sbin/nologin\n", + "news:x:9:9:news:/var/spool/news:/usr/sbin/nologin\n", + "uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin\n", + "proxy:x:13:13:proxy:/bin:/usr/sbin/nologin\n", + "www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin\n", + "backup:x:34:34:backup:/var/backups:/usr/sbin/nologin\n", + "list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin\n", + "irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin\n", + "gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin\n", + "nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin\n", + "_apt:x:100:65534::/nonexistent:/usr/sbin/nologin\n", + "systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin\n", + "systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin\n", + "messagebus:x:103:107::/nonexistent:/usr/sbin/nologin\n", + "nvidia-persistenced:x:104:108:NVIDIA Persistence Daemon,,,:/nonexistent:/sbin/nologin\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep --help\n", + "Usage: grep [OPTION]... PATTERN [FILE]...\n", + "Search for PATTERN in each FILE.\n", + "Example: grep -i 'hello world' menu.h main.c\n", + "\n", + "Pattern selection and interpretation:\n", + " -E, --extended-regexp PATTERN is an extended regular expression\n", + " -F, --fixed-strings PATTERN is a set of newline-separated strings\n", + " -G, --basic-regexp PATTERN is a basic regular expression (default)\n", + " -P, --perl-regexp PATTERN is a Perl regular expression\n", + " -e, --regexp=PATTERN use PATTERN for matching\n", + " -f, --file=FILE obtain PATTERN from FILE\n", + " -i, --ignore-case ignore case distinctions\n", + " -w, --word-regexp force PATTERN to match only whole words\n", + " -x, --line-regexp force PATTERN to match only whole lines\n", + " -z, --null-data a data line ends in 0 byte, not newline\n", + "\n", + "Miscellaneous:\n", + " -s, --no-messages suppress error messages\n", + " -v, --invert-match select non-matching lines\n", + " -V, --version display version information and exit\n", + " --help display this help text and exit\n", + "\n", + "Output control:\n", + " -m, --max-count=NUM stop after NUM selected lines\n", + " -b, --byte-offset print the byte offset with output lines\n", + " -n, --line-number print line number with output lines\n", + " --line-buffered flush output on every line\n", + " -H, --with-filename print file name with output lines\n", + " -h, --no-filename suppress the file name prefix on output\n", + " --label=LABEL use LABEL as the standard input file name prefix\n", + " -o, --only-matching show only the part of a line matching PATTERN\n", + " -q, --quiet, --silent suppress all normal output\n", + " --binary-files=TYPE assume that binary files are TYPE;\n", + " TYPE is 'binary', 'text', or 'without-match'\n", + " -a, --text equivalent to --binary-files=text\n", + " -I equivalent to --binary-files=without-match\n", + " -d, --directories=ACTION how to handle directories;\n", + " ACTION is 'read', 'recurse', or 'skip'\n", + " -D, --devices=ACTION how to handle devices, FIFOs and sockets;\n", + " ACTION is 'read' or 'skip'\n", + " -r, --recursive like --directories=recurse\n", + " -R, --dereference-recursive likewise, but follow all symlinks\n", + " --include=FILE_PATTERN search only files that match FILE_PATTERN\n", + " --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN\n", + " --exclude-from=FILE skip files matching any file pattern from FILE\n", + " --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n", + " -L, --files-without-match print only names of FILEs with no selected lines\n", + " -l, --files-with-matches print only names of FILEs with selected lines\n", + " -c, --count print only a count of selected lines per FILE\n", + " -T, --initial-tab make tabs line up (if needed)\n", + " -Z, --null print 0 byte after FILE name\n", + "\n", + "Context control:\n", + " -B, --before-context=NUM print NUM lines of leading context\n", + " -A, --after-context=NUM print NUM lines of trailing context\n", + " -C, --context=NUM print NUM lines of output context\n", + " -NUM same as --context=NUM\n", + " --color[=WHEN],\n", + " --colour[=WHEN] use markers to highlight the matching strings;\n", + " WHEN is 'always', 'never', or 'auto'\n", + " -U, --binary do not strip CR characters at EOL (MSDOS/Windows)\n", + "\n", + "When FILE is '-', read standard input. With no FILE, read '.' if\n", + "recursive, '-' otherwise. With fewer than two FILEs, assume -h.\n", + "Exit status is 0 if any line is selected, 1 otherwise;\n", + "if any error occurs and -q is not given, the exit status is 2.\n", + "\n", + "Report bugs to: bug-grep@gnu.org\n", + "GNU grep home page: \n", + "General help using GNU software: \n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -i 'w' /etc/passwd\n", + "ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:x:9:9:ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:/var/spool/ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:/usr/sbin/nologin\n", + "\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K-data:x:33:33:\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K-data:/var/\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K:/usr/sbin/nologin\n", + "systemd-net\u001b[01;31m\u001b[Kw\u001b[m\u001b[Kork:x:101:104:systemd Net\u001b[01;31m\u001b[Kw\u001b[m\u001b[Kork Management,,,:/run/systemd/netif:/usr/sbin/nologin\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -c 'w' /etc/passwd\n", + "3\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SZuhLbD8qvz5", + "colab_type": "text" + }, + "source": [ + "## Redirection\n", + "\n", + "Unix provides programs \"pipes\" for input and output. Most of what you see on the screen when you run a program was written to the \"stdout\" (standard output) pipe. Other pipes are \"stdin\" (standard input) and \"stderr\" (standard error), where error messages are written.\n", + "\n", + "As discussed in lecture, the basic commands of are simple, but you can chain them to do complicated things. Redirection is how you chain these commands, directing the output of one command to the input of the next.\n", + "\n", + "As an example, consider the \"cat\" command. Cat takes stdin and outputs it to stdout. Type \"cat\" and press enter and confirm. You can get back to the command prompt by pressing \"control-c\" (sends terminate singal) or \"control-d\" (end of file character). Note that from now on we will use the convention: \"control-d\" = \"^D\"\n", + "\n", + "*Exercise 5a:* Using \"cat\" and indirection you can write things into a file. The \">\" symbol directs stdout into a file. Try \"cat > favorite-colors-list.txt\" and then type in your 3 favorite colors, each on it's own line. Use \"^D\" to end your input." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H5vxtcXnqvz6", + "colab_type": "text" + }, + "source": [ + "Use \"cat\", \"more\", or \"less\" to confirm that you file is as you expect it. \">>\" allows you to append to the file. \n", + "\n", + "*Exercise 5b:* Append 2 more colors to your file." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "twRKNaGy3XGw", + "colab_type": "code", + "outputId": "763bf004-b6e0-4761-b43c-ec3d41d2b707", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat > favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# \n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"white\"\n", + "white\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"white\" >> favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"pink\" >> favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "white\n", + "pink\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DZODNKiAqvz8", + "colab_type": "text" + }, + "source": [ + "The \"sort\" command sorts what it sees on stdin. Instead of taking input from the terminal, you can direct the shell to take stdin from a file using \"<\". Try \"sort < favorite-color-list.txt\" and \"sort < favorite-color-list.txt > sorted-favorite-color-list.txt\".\n", + "\n", + "Finally, instead of piping input / output into files, you can directly chain one program into another using \"|\". So for example, you can do \"cat /etc/passwd | grep -i \\$USER | wc -l\". \n", + "\n", + "*Exercise 5c:* Use indirection to count the number of users on TACC with your first name. Copy the command you used into box below." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "oP9XlZl_3iZD", + "colab_type": "code", + "outputId": "c917ad7f-3638-43ae-ad7e-a22664413a68", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 306 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# sort < favoritecolors\n", + "blue\n", + "pink\n", + "purple\n", + "white\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# sort < favoritecolors > sorted_favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat sorted_favoritecolors\n", + "blue\n", + "pink\n", + "purple\n", + "white\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "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": "85c2adaa-9c46-43e8-9537-17b96ee170a4", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + } + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive\n", + "'Colab Notebooks' 'Freshmen year' 'HW1 Answers.gdoc'\n", + " Data-1401\t Highschool\t SPAN\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": "3bed7b00-53c6-481e-98b9-a5b49d904788", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fwsBdTnYqv0Q", + "colab_type": "text" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8w42MH6Jqv0S", + "colab_type": "code", + "outputId": "b9d30373-a331-4802-9fa9-485a0d703988", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "# What you past here should look like:\n", + "#!git clone https://github.com//DATA1401-Spring-2020.git\n", + "!git clone https://github.com/bridgetg19/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Cloning into 'DATA1401-Spring-2020'...\n", + "remote: Enumerating objects: 38, done.\u001b[K\n", + "remote: Counting objects: 100% (38/38), done.\u001b[K\n", + "remote: Compressing objects: 100% (25/25), done.\u001b[K\n", + "remote: Total 38 (delta 7), reused 36 (delta 5), pack-reused 0\u001b[K\n", + "Unpacking objects: 100% (38/38), done.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cOAuqTVUqv0V", + "colab_type": "text" + }, + "source": [ + "Go into the directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "b1Ew4tEZqv0X", + "colab_type": "code", + "outputId": "c601d630-ee66-4990-8be0-260d7024a44e", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "%cd DATA1401-Spring-2020\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo/DATA1401-Spring-2020\n", + "Labs Lectures\tREADME.md syllabus.pdf\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IrhWToc-qv0a", + "colab_type": "text" + }, + "source": [ + "We will now connect your fork to the original so you can pull changes from there. \n", + "\n", + "Check remote status:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JxtMYR-9qv0c", + "colab_type": "code", + "outputId": "daa7bd38-d492-40d4-fbbf-5fcf56d5a8bf", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/bridgetg19/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", + "outputId": "1c6a6ea5-655e-4068-dd1c-2f987adc67c1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "fatal: remote upstream already exists.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "id2yUEt9qv0k", + "colab_type": "code", + "outputId": "fcf1e13a-d105-463a-925a-2eb9724d8033", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (push)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (fetch)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sAkgeJ6Iqv0n", + "colab_type": "text" + }, + "source": [ + "From now on, you can get the newest version of class material by using:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AGDsfTFLqv0o", + "colab_type": "code", + "outputId": "ac4c023e-0a28-4057-ca87-0c0c231463d1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!git pull" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Already up to date.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u9RAhs5b4vXY", + "colab_type": "text" + }, + "source": [ + "We will submit your Lab 1 using git at the next Lab." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PPfGmFQI40HR", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Exams/Final/Final_Solutions.ipynb b/Exams/Final/Final_Solutions.ipynb new file mode 100644 index 0000000..4ace267 --- /dev/null +++ b/Exams/Final/Final_Solutions.ipynb @@ -0,0 +1,1247 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.0" + }, + "colab": { + "name": "Copy of Final.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "uXYcSv-tqn1_", + "colab_type": "text" + }, + "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": { + "id": "D0_UjjwJqn2A", + "colab_type": "text" + }, + "source": [ + "Recall the drawing system from lecture 18:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "QnL2Lgixqn2A", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#I changed the Canvas class bc the horizontal and vertical lines were reversed and i moved\n", + "# the origin from the top left to the bottom left when displayed\n", + "\n", + "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='*', pr=False, **kwargs):\n", + " if pr:\n", + " print(\"set pixel: (\",col,\",\",row,\")\")\n", + " self.data[col][row]=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", + " # keep the row constant\n", + " #self.set_pixel(i,y, **kargs)\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", + " # keep the column constant\n", + " #self.set_pixel(x,i, **kargs)\n", + " self.set_pixel(x,i, **kargs)\n", + " \n", + " def line(self, x1, y1, x2, y2, **kargs):\n", + " #y2 nees to be > than y1 or it wont set the pixels\n", + " slope = (y2-y1) / (x2-x1)\n", + " for y in range(y1,y2):\n", + " x= int(slope * y)\n", + " self.set_pixel(x,y, **kargs)\n", + " \n", + " \n", + " def display(self):\n", + " # added reversed() so that the 2d matrix is printed correctly with the\n", + " # origin in the lower left corner.\n", + " print(\"\\n\".join([\".\".join(row) for row in reversed(self.data)]))\n", + " #print(\"\\n\".join([\".\".join(row) for row in self.data])) " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "HkMTBUgLjTK6", + "colab_type": "code", + "outputId": "3a404015-b76a-4ec5-b76a-8646b19e47d7", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 357 + } + }, + "source": [ + "c=Canvas(20,20)\n", + "# verify the origin is in the lower left corner\n", + "c.set_pixel(0,0,'&') \n", + "c.set_pixel(19,19,'e')\n", + "c.h_line(2,2,5)\n", + "c.v_line(2,2,5)\n", + "c.line(6,2,2,6)\n", + "c.display()" + ], + "execution_count": 2, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . .e\n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . .*. . . . . . . . . . . . . . . . . \n", + " . .*. . . . . . . . . . . . .*. . . . \n", + " . .*. . . . . . . . . . . . . .*. . . \n", + " . .*. . . . . . . . . . . . . . .*. . \n", + " . .*.*.*.*.*. . . . . . . . . . . .*. \n", + " . . . . . . . . . . . . . . . . . . . \n", + "&. . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ZY4cvjGAqn2E", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#i modified the rectangle class bc the right side doesnt paint properly\n", + "class Shape:\n", + " def __init__(self, name=\"\", **kwargs):\n", + " self.name=name\n", + " self.kwargs=kwargs\n", + " \n", + " def paint(self, canvas):\n", + " pass\n", + "\n", + " def __str__(self):\n", + " pass\n", + "\n", + "class Rectangle(Shape):\n", + " def __init__(self, x, y, w, h, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x = x\n", + " self.y = y\n", + " self.w = w\n", + " self.h = h\n", + "\n", + " def paint(self, canvas,points=0):\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-1), self.y, self.h, **self.kwargs)\n", + "\n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt=\"Rectangle({:d},{:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.x, self.y,self.w, self.h, self.name,myChar))\n", + "\n", + "class Square(Rectangle):\n", + " def __init__(self, x, y, size, **kwargs):\n", + " Rectangle.__init__(self, x, y, size, size, **kwargs)\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Square({:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.x,self.y,self.w,self.name,myChar))\n", + "\n", + "\n", + "class Line(Shape):\n", + " def __init__(self, x1, y1, x2, y2, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x1=x1\n", + " self.y1=y1\n", + " self.x2=x2\n", + " self.y2=y2\n", + " \n", + " def paint(self, canvas,points=0):\n", + " canvas.line(self.x1,self.y1,self.x2,self.y2)\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Line({:d},{:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.x1,self.y1,self.x2,self.y2,self.name,myChar))\n", + " \n", + "class CompoundShape(Shape):\n", + " def __init__(self, shapes, name=\"\", **kwargs):\n", + " self.shapes = shapes\n", + " Shape.__init__(self, **kwargs)\n", + "\n", + " def paint(self, canvas, **kwargs):\n", + " for s in self.shapes:\n", + " s.paint(canvas, **kwargs)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nrOEwalIazDO", + "colab_type": "code", + "outputId": "0a3373f4-e4a6-424f-d875-e785eef7f80e", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 357 + } + }, + "source": [ + "c=Canvas(20,20)\n", + "\n", + "rect1=Rectangle(2,2,5,3,char='&')\n", + "rect1.paint(c)\n", + "\n", + "sq1=Square(10,10,6)\n", + "sq1.paint(c)\n", + "\n", + "c.display()" + ], + "execution_count": 4, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . .*.*.*.*.*.*. . . . \n", + " . . . . . . . . . .*. . . . .*. . . . \n", + " . . . . . . . . . .*. . . . .*. . . . \n", + " . . . . . . . . . .*. . . . .*. . . . \n", + " . . . . . . . . . .*. . . . .*. . . . \n", + " . . . . . . . . . .*. . . . .*. . . . \n", + " . . . . . . . . . .*.*.*.*.*.*. . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "VnJFWizEqn2G", + "colab_type": "code", + "colab": {} + }, + "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,**kwargs):\n", + " for shape_name in self.shape_names:\n", + " self.shapes[shape_name].paint(canvas,**kwargs)\n", + " \n", + " def assign_name(self):\n", + " name_base=\"shape\"\n", + " name = name_base+\"_0\"\n", + " \n", + " i=1\n", + " while name in self.shapes:\n", + " name = name_base+\"_\"+str(i)\n", + " i+=1\n", + " #added increment for while loop\n", + "\n", + " return name\n", + "\n", + " def list(self):\n", + " for shape_name in self.shape_names: \n", + " print(self.shapes[shape_name].name)\n", + " \n", + " def save(self, filename):\n", + " with open(filename,'w',encoding = 'utf-8') as f:\n", + " for shape_name in self.shape_names: \n", + " print(self.shapes[shape_name], file=f)\n", + " f.close()\n", + " \n", + " def load(self, filename):\n", + " f=open(filename, \"r\")\n", + " try:\n", + " f=open(filename, encoding='utf-8')\n", + " for line in f:\n", + " shape=eval(line.rstrip())\n", + " self.add_shape(shape)\n", + " finally:\n", + " f.close()\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "nqackZ1kqn2J", + "colab_type": "text" + }, + "source": [ + "1. Add `Point` and `Triangle` classes and test them." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PwaK6JBBqn2J", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class Point(Shape):\n", + " def __init__(self, x, y, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x=x\n", + " self.y=y\n", + " \n", + " def paint(self, canvas, **kwargs):\n", + " canvas.set_pixel(self.x,self.y,**self.kwargs)\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Point({:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.x,self.y,self.name,myChar))\n", + "\n", + "\n", + "#for a right triangle \n", + "class Triangle(Shape):\n", + " def __init__(self, x, y, b, h, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.x=x\n", + " self.y=y\n", + " self.b=b\n", + " self.h=h\n", + " \n", + " def paint(self, canvas,**kwargs):\n", + " canvas.h_line(self.x, self.y, self.h, **self.kwargs)\n", + " canvas.v_line(self.x+self.h, self.y, self.b, **self.kwargs)\n", + " canvas.line(self.x,self.y,self.x+self.b,self.y+self.h, **self.kwargs)\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Triangle({:d},{:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.x,self.y,self.b,self.h,self.name,myChar))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "T9wduqQsy1xH", + "colab_type": "code", + "outputId": "654e7dbc-92cb-40c1-b412-2e12e0cba574", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 357 + } + }, + "source": [ + "c2=Canvas(20,20)\n", + "\n", + "p1=Point(5,5,char='+')\n", + "p1.paint(c2)\n", + "\n", + "t1=Triangle(11,11,6,6,char='&')\n", + "t1.paint(c2)\n", + "\n", + "c2.display()" + ], + "execution_count": 7, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . .&.&. . \n", + " . . . . . . . . . . . . . . .&. .&. . \n", + " . . . . . . . . . . . . . .&. . .&. . \n", + " . . . . . . . . . . . . .&. . . .&. . \n", + " . . . . . . . . . . . .&. . . . .&. . \n", + " . . . . . . . . . . .&.&.&.&.&.&.&. . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . .+. . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "h5bk0NtFqn2M", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "yhe3h0Owk-ej", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import math\n", + "\n", + "#counterclockwise orientation for angle def (in degrees)\n", + "class Arc(Shape):\n", + " def __init__(self, centerX, centerY, axisA, axisB, start=0, end=2*math.pi, **kwargs):\n", + " Shape.__init__(self, **kwargs)\n", + " self.center=Point(centerX, centerY, **kwargs)\n", + " self.axisA=axisA\n", + " self.axisB=axisB\n", + " self.start=start\n", + " self.end=end\n", + " \n", + " def paint(self, canvas, points=4, **kwargs):\n", + " arc=(self.end-self.start)/points\n", + "\n", + " for i in range(points):\n", + " t=self.start+(arc*(i))\n", + " ptX=self.center.x+(self.axisA*math.cos(t))\n", + " ptY=self.center.y+(self.axisB*math.sin(t))\n", + "\n", + " canvas.set_pixel(math.ceil(ptX),math.ceil(ptY), **self.kwargs)\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Arc({:d},{:d},{:d},{:d},{:f},{:f},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.center.x,self.center.y,self.axisA,self.axisB,\n", + " self.start,self.end,self.name,myChar))\n", + "\n", + "\n", + "class Circle(Arc):\n", + " def __init__(self, centerX, centerY, len1, start=0, end=0, **kwargs):\n", + " Arc.__init__(self, centerX, centerY, len1, len1, start=0, end=2*math.pi,**kwargs)\n", + " self.radius=len1\n", + "\n", + " def get_radius(self):\n", + " return self.radius\n", + " \n", + "\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Circle({:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.center.x,self.center.y,self.radius,self.name,myChar))\n", + "\n", + "\n", + "class Oval(Arc):\n", + " def __init__(self, centerX, centerY, len1, len2, start=0, end=0, **kwargs):\n", + " Arc.__init__(self, centerX, centerY, len1, len2, **kwargs)\n", + " self.len1=len1\n", + " self.len2=len2\n", + " \n", + " def __str__(self):\n", + " if \"char\" in self.kwargs:\n", + " myChar=self.kwargs[\"char\"]\n", + " else:\n", + " myChar=\"*\"\n", + " instantiateTxt = \"Oval({:d},{:d},{:d},{:d},name='\"'{:s}'\"',char='\"'{:s}'\"')\"\n", + " return(instantiateTxt.format(self.center.x,self.center.y,self.len1,self.len2,\n", + " self.name,myChar))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "UXPhxmO_QBRk", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 527 + }, + "outputId": "10e82107-ab95-4b3d-e397-86a906a5716f" + }, + "source": [ + "#Test arc\n", + "c4=Canvas(30,30)\n", + "a1=Arc(15,18,10,5,math.pi,2*math.pi)\n", + "a1.paint(c4,points=10)\n", + "c4.display()" + ], + "execution_count": 9, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . .*. . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . .*. . . . . . . . . . . . . . . . . . .*. . . . \n", + " . . . . . . .*. . . . . . . . . . . . . . . . .*. . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . .*. .*. . . . . . .*. .*. . . . . . . . \n", + " . . . . . . . . . . . . . . .*. . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5_BtRkKQrhDH", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 357 + }, + "outputId": "137bbdb4-5740-4797-8b74-669ee41cf9b9" + }, + "source": [ + "#Test circle\n", + "canvas3=Canvas(20,20)\n", + "\n", + "rd=RasterDrawing()\n", + "rd.add_shape(Circle(10,10,5,char='@'))\n", + "rd.paint(canvas3,points=50)\n", + "canvas3.display()" + ], + "execution_count": 10, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . .@.@.@.@.@.@. . . . . . \n", + " . . . . . . .@. . . . . . .@. . . . . \n", + " . . . . . .@. . . . . . . . .@. . . . \n", + " . . . . . .@. . . . . . . . .@. . . . \n", + " . . . . . .@. . . . . . . . .@. . . . \n", + " . . . . .@.@. . . . . . . . .@. . . . \n", + " . . . . . .@. . . . . . . . .@. . . . \n", + " . . . . . .@. . . . . . . . .@. . . . \n", + " . . . . . . .@. . . . . . .@. . . . . \n", + " . . . . . . . .@.@.@.@.@.@. . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YQGFUL0zShBU", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 527 + }, + "outputId": "e3ea581a-f116-47e8-b9ce-16e42e6020b3" + }, + "source": [ + "#Test oval\n", + "c5=Canvas(30,30)\n", + "\n", + "rd=RasterDrawing()\n", + "rd.add_shape(Oval(15,15,12,6))\n", + "rd.paint(c5,points=25)\n", + "c5.display()" + ], + "execution_count": 11, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . .*. . .*. . .*. . .*. . .*. . . . . . . \n", + " . . . . . . . .*. . . . . . . . . . . . . . . .*. . . . . \n", + " . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . .*. . . . . . . . . . . . . . . . . . . . . .*. . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . \n", + " . . . .*. . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . .*. . . . . . . . . . . . . . . . . . . . . . .*. . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . \n", + " . . . .*. . . . . . . . . . . . . . . . . . . . . .*. . . \n", + " . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . .*. . . . . . . . . . . . . . . .*. . . . . \n", + " . . . . . . . . . .*. . .*. . .*. . .*. . .*. . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dlUBRlRxqn2P", + "colab_type": "text" + }, + "source": [ + "3. Use your classes to create a `RasterDrawing` that draws a happy face." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "m6FcfTXPs-VV", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 867 + }, + "outputId": "2c84bad9-b534-4007-a45c-855c80235977" + }, + "source": [ + "c=Canvas(50,50)\n", + "smileyFace=CompoundShape([Circle(25,25,20),\n", + " Oval(33,31,3,5,char='o'),\n", + " Oval(17, 31, 3, 5,char='o'),\n", + " Arc(25,20,10,5,math.pi,char='&')])\n", + "rd=RasterDrawing()\n", + "rd.add_shape(smileyFace)\n", + "smileyFace.paint(c,points=50)\n", + "rd.paint(c, points=8)\n", + "c.display()" + ], + "execution_count": 12, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . .*. . .*. .*.*. .*. .*. . .*. . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . .*. . . . . . . . . . . . . . . . .*. . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . .*. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . . .*. . . . . . . . . . . \n", + " . . . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . . . . . . . . \n", + " . . . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . .*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*. . . . . . . \n", + " . . . . . . . . . . . . . . . .o.o.o.o. . . . . . . . . . . . .o.o.o.o. . . . . . . . . . . . . . \n", + " . . . . . . . .*. . . . . . .o.o. . .o.o. . . . . . . . . . .o.o. . .o.o. . . . . . .*. . . . . . \n", + " . . . . . . . . . . . . . . .o. . . . .o. . . . . . . . . . .o. . . . .o. . . . . . . . . . . . . \n", + " . . . . . . .*. . . . . . . .o. . . . .o. . . . . . . . . . .o. . . . .o. . . . . . . .*. . . . . \n", + " . . . . . . . . . . . . . . .o. . . . .o. . . . . . . . . . .o. . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . .o.o. . . . .o. . . . . . . . . .o.o. . . . .o. . . . . . . . . . . . . \n", + " . . . . . .*. . . . . . . . .o. . . . .o. . . . . . . . . . .o. . . . .o. . . . . . . . .*. . . . \n", + " . . . . . . . . . . . . . . .o. . . . .o. . . . . . . . . . .o. . . . .o. . . . . . . . . . . . . \n", + " . . . . . .*. . . . . . . . .o.o. . .o.o. . . . . . . . . . .o.o. . .o.o. . . . . . . . .*. . . . \n", + " . . . . . . . . . . . . . . . .o.o.o.o. . . . . . . . . . . . .o.o.o.o. . . . . . . . . . . . . . \n", + " . . . . .*. . . . . . . . . . . .o. . . . . . . . . . . . . . . .o. . . . . . . . . . . . . . . . \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" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "t_dcil1rqn2T", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "_jciqEC1azaD", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + }, + "outputId": "b13cc1d1-f9bd-446e-bfd6-a100fe9c015b" + }, + "source": [ + "r1=Rectangle(2,40,5,3,name=\"r1\",char=\"&\")\n", + "s1=Square(4,4,6,name=\"sq1\")\n", + "l1=Line(7,2,2,9,name=\"line1\",char=\"^\")\n", + "p1=Point(5,5,name=\"point1\",char='+')\n", + "t1=Triangle(11,11,6,6,name=\"tri1\",char='&')\n", + "a1=Arc(25,18,10,5,math.pi,2*math.pi,char='*')\n", + "c1=Circle(25,25,20,name=\"circ1\",char='@')\n", + "o1=Oval(31,31,5,7,name=\"ov1\",char='o')\n", + "\n", + "print(r1)\n", + "print(s1)\n", + "print(l1)\n", + "print(p1)\n", + "print(t1)\n", + "print(a1)\n", + "print(c1)\n", + "print(o1)" + ], + "execution_count": 13, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Rectangle(2,40,5,3,name='r1',char='&')\n", + "Square(4,4,6,name='sq1',char='*')\n", + "Line(7,2,2,9,name='line1',char='^')\n", + "Point(5,5,name='point1',char='+')\n", + "Triangle(11,11,6,6,name='tri1',char='&')\n", + "Arc(25,18,10,5,3.141593,6.283185,name='',char='*')\n", + "Circle(25,25,20,name='circ1',char='@')\n", + "Oval(31,31,5,7,name='ov1',char='o')\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "CGC4OL7Vqn2W", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "tJjH_cYKZcAp", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + }, + "outputId": "80faa5a4-20cb-403e-9c60-637632b852d5" + }, + "source": [ + "r1=Rectangle(2,40,5,3,name=\"r1\",char=\"&\")\n", + "s1=Square(4,4,6,name=\"sq1\")\n", + "l1=Line(7,2,2,9,name=\"line1\",char=\"^\")\n", + "p1=Point(5,5,name=\"point1\",char='+')\n", + "t1=Triangle(11,11,6,6,name=\"tri1\",char='&')\n", + "a1=Arc(25,18,10,5,math.pi,2*math.pi,char='*')\n", + "c1=Circle(25,25,20,name=\"circ1\",char='@')\n", + "o1=Oval(31,31,5,7,name=\"ov1\",char='o')\n", + "\n", + "print(eval(\"r1\"))\n", + "print(eval(\"s1\"))\n", + "print(eval(\"l1\"))\n", + "print(eval(\"p1\"))\n", + "print(eval(\"t1\"))\n", + "print(eval(\"a1\"))\n", + "print(eval(\"c1\"))\n", + "print(eval(\"o1\"))" + ], + "execution_count": 14, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Rectangle(2,40,5,3,name='r1',char='&')\n", + "Square(4,4,6,name='sq1',char='*')\n", + "Line(7,2,2,9,name='line1',char='^')\n", + "Point(5,5,name='point1',char='+')\n", + "Triangle(11,11,6,6,name='tri1',char='&')\n", + "Arc(25,18,10,5,3.141593,6.283185,name='',char='*')\n", + "Circle(25,25,20,name='circ1',char='@')\n", + "Oval(31,31,5,7,name='ov1',char='o')\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "pmufYTNUbGjS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 867 + }, + "outputId": "ab61dddd-edd4-4050-c77b-1f7eebdc8ac5" + }, + "source": [ + "c=Canvas(50,50)\n", + "\n", + "r2=eval(\"r1\")\n", + "s2 = eval(\"s1\")\n", + "l2 = eval(\"l1\")\n", + "p2 = eval(\"p1\")\n", + "t2 = eval(\"t1\")\n", + "a2 = eval(\"a1\")\n", + "c2 = eval(\"c1\")\n", + "o2 = eval(\"o1\")\n", + "\n", + "r2.paint(c)\n", + "s2.paint(c)\n", + "l2.paint(c)\n", + "p2.paint(c)\n", + "t2.paint(c)\n", + "a2.paint(c,points=20)\n", + "c2.paint(c,points=20)\n", + "o2.paint(c,points=20)\n", + "\n", + "c.display()" + ], + "execution_count": 15, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . .@. . . . . .@. . . . . . .@. . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . .@. . . . . . . . . . . . . . . . . . . . . . .@. . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o.o. .o. . . . . . . . . . . . . . . . \n", + " . . . . . . . . .@. . . . . . . . . . . . . . . . . . . .o. . . . .o. . . . . . . .@. . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . .@. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .@. . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . .@. . . . . . . . . . . . . . . . . . . . . . . .o. . . . .o. . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . .o. . . . . . . . . . . .@. . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . . . . . . . . . . . \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" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "MXY6IeodbWsS", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + }, + "outputId": "38f41a0f-2eeb-4237-87c7-9936c587c7cc" + }, + "source": [ + "#add shapes to RasterDrawing() obj and save to a file\n", + "rd1=RasterDrawing()\n", + "\n", + "rd1.add_shape(r2)\n", + "rd1.add_shape(s2)\n", + "rd1.add_shape(l2)\n", + "rd1.add_shape(p2)\n", + "rd1.add_shape(t2)\n", + "rd1.add_shape(a2)\n", + "rd1.add_shape(c2)\n", + "rd1.add_shape(o2)\n", + "\n", + "\n", + "rd1.list()\n", + "rd1.save(\"shapes_file.txt\")" + ], + "execution_count": 16, + "outputs": [ + { + "output_type": "stream", + "text": [ + "r1\n", + "sq1\n", + "line1\n", + "point1\n", + "tri1\n", + "shape_0\n", + "circ1\n", + "ov1\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "N2sMXnMkmj4z", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + }, + "outputId": "c73bb3b5-10cf-45fb-e4a1-957bee2615b3" + }, + "source": [ + "rd2=RasterDrawing()\n", + "rd2.list()\n", + "rd2.load(\"shapes_file.txt\")\n", + "rd2.list()" + ], + "execution_count": 17, + "outputs": [ + { + "output_type": "stream", + "text": [ + "r1\n", + "sq1\n", + "line1\n", + "point1\n", + "tri1\n", + "shape_0\n", + "circ1\n", + "ov1\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "wxfoYxnFchEL", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 867 + }, + "outputId": "198f4426-520c-458e-e7dd-a3d4b299390b" + }, + "source": [ + "c3=Canvas(50,50)\n", + "rd2.paint(c3,points=20)\n", + "c3.display()" + ], + "execution_count": 18, + "outputs": [ + { + "output_type": "stream", + "text": [ + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . .@. . . . . .@. . . . . . .@. . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . .@. . . . . . . . . . . . . . . . . . . . . . .@. . . . . . . . . . . . \n", + " . .&. . . .&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . .&.&.&.&.&. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o.o. .o. . . . . . . . . . . . . . . . \n", + " . . . . . . . . .@. . . . . . . . . . . . . . . . . . . .o. . . . .o. . . . . . . .@. . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . .@. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .@. . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . .o. . . . . . . . . . . . . \n", + " . . . . .@. . . . . . . . . . . . . . . . . . . . . . . .o. . . . .o. . . . . . . . . . . . . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . .o. . . . . . . . . . . .@. . . . \n", + " . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .o. . . . . . . . . . . . . . . . . . \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" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "HJLB8Xk8qn2W", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "7da5a9a8-4481-4635-9741-800694342a49" + }, + "source": [ + "eval(\"print('Hello')\")" + ], + "execution_count": 19, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Hello\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xyn0mFG6qn2Z", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "outputId": "67298e79-3c4f-41b8-9c20-d3ee7cb13304" + }, + "source": [ + "x = eval('1+2')\n", + "print(x)" + ], + "execution_count": 20, + "outputs": [ + { + "output_type": "stream", + "text": [ + "3\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "fTYeDkFxqn2b", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Exams/Mid-term/Exam_Solutions.ipynb b/Exams/Mid-term/Exam_Solutions.ipynb new file mode 100644 index 0000000..22fe60a --- /dev/null +++ b/Exams/Mid-term/Exam_Solutions.ipynb @@ -0,0 +1,674 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.1" + }, + "colab": { + "name": "Copy of Exam.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "xswOJARsR7My", + "colab_type": "text" + }, + "source": [ + "# Mid-term Exam\n", + "\n", + "Add cells to this notebook as you need for you solutions and your test of your solutions." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "oQdYIqm3R7Mz", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "A0PBarVKR7M0", + "colab_type": "code", + "colab": {} + }, + "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']" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "04pQ9NnyR7M3", + "colab_type": "text" + }, + "source": [ + "should return the string `\"Alabama\"`. Note that you can compare strings:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "gmnDirsgR7M4", + "colab_type": "code", + "outputId": "c15aa9ce-bf52-4314-992f-6b8a7376f0a3", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "print(\"A\">\"B\")\n", + "print(\"B\">\"A\")\n", + "print(\"A\">\"a\")\n", + "print(\"bca\">\"bbc\")\n", + "states[0].lower()" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "False\n", + "True\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'mississippi'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 25 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "CIsJOx4zUxwl", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def first_alphabetically(lst):\n", + " lowest=lst[0]\n", + " for i in range(len(lst)):\n", + " test=lst[i]\n", + " if test0:\n", + " for index, element in enumerate(lst):\n", + " low_index=arg_first_alphabetically(lst)\n", + " low_word=first_alphabetically(lst)\n", + " out.append(low_word)\n", + " lst.pop(low_index)\n", + "\n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3cS_VxLzYR3d", + "colab_type": "code", + "outputId": "570ab84b-7318-48e8-c96f-3d8ce35dfb71", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 867 + } + }, + "source": [ + "arg_sort_alphabetically(states)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "['Alabama',\n", + " 'Alaska',\n", + " 'Arizona',\n", + " 'Arkansas',\n", + " 'California',\n", + " 'Colorado',\n", + " 'Connecticut',\n", + " 'Delaware',\n", + " 'Florida',\n", + " 'Georgia',\n", + " 'Hawaii',\n", + " 'Idaho',\n", + " 'Illinois',\n", + " 'Indiana',\n", + " 'Iowa',\n", + " 'Kansas',\n", + " 'Kentucky',\n", + " 'Louisiana',\n", + " 'Maine',\n", + " 'Maryland',\n", + " 'Massachusetts',\n", + " 'Michigan',\n", + " 'Minnesota',\n", + " 'Mississippi',\n", + " 'Missouri',\n", + " 'Montana',\n", + " 'Nebraska',\n", + " 'Nevada',\n", + " 'New Hampshire',\n", + " 'New Jersey',\n", + " 'New Mexico',\n", + " 'New York',\n", + " 'North Carolina',\n", + " 'North Dakota',\n", + " 'Ohio',\n", + " 'Oklahoma',\n", + " 'Oregon',\n", + " 'Pennsylvania',\n", + " 'Rhode Island',\n", + " 'South Carolina',\n", + " 'South Dakota',\n", + " 'Tennessee',\n", + " 'Texas',\n", + " 'Utah',\n", + " 'Vermont',\n", + " 'Virginia',\n", + " 'Washington',\n", + " 'West Virginia',\n", + " 'Wisconsin',\n", + " 'Wyoming']" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 163 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "zBth4MnDR7M8", + "colab_type": "text" + }, + "source": [ + "4. Implement a function `outer_product` that takes two one-dimensional lists of numbers and returns the two-dimensional outer product matrix defined as:\n", + "\n", + "\\begin{equation*}\n", + "\\begin{pmatrix} x_1\\\\x_2\\\\ \\vdots \\\\x_m \\end{pmatrix} \\begin{pmatrix} y_1&y_2& \\dots &y_n\\end{pmatrix} =\n", + "\\begin{pmatrix}\n", + "x_1y_1 & x_1y_2 & \\dots & x_1y_n\\\\\n", + "x_2y_1 & x_2y_2 & \\dots & x_2y_n\\\\\n", + "\\vdots & \\vdots & \\ddots & \\vdots \\\\\n", + "x_my_1 & x_my_2 & \\dots & x_my_n\n", + "\\end{pmatrix}\n", + "\\end{equation*}\n", + "\n", + "In other words the elements of matrix C which is the outer product of A and B are $c_{ij} = a_i b_j$." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "owC5qldKfa7I", + "colab_type": "code", + "outputId": "dc573b26-73cd-4330-97ac-ad0b08a242ae", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "def zero_matrix(m,n):\n", + " out=list()\n", + " for i in range(m):\n", + " row=list()\n", + " for j in range(n):\n", + " row.append(0)\n", + " out.append(row)\n", + " return out\n", + "\n", + "zero_matrix(3,3)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[[0, 0, 0], [0, 0, 0], [0, 0, 0]]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 156 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "D55u1sEmc0Z9", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def outer_product(a,b):\n", + " row_a=len(a)\n", + " col_b=len(b)\n", + " M_out=zero_matrix(row_a,col_b)\n", + " out=[]\n", + "\n", + " for i in range(row_a):\n", + " for j in range(col_b):\n", + " M_out[i][j]+=a[i]*b[j]\n", + "\n", + " return M_out\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "aDE9CS-6c02p", + "colab_type": "code", + "colab": {} + }, + "source": [ + "B=[1,2,3]\n", + "A=[2,4,6]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "p-g1RN3Ojg2W", + "colab_type": "code", + "outputId": "d4f3f5d9-3582-4a17-ceb3-a124d44e9562", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "outer_product(A,B)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[[2, 4, 6], [4, 8, 12], [6, 12, 18]]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 159 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "UiSoGABUpU2W", + "colab_type": "text" + }, + "source": [ + "" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3dOQyEcER7M8", + "colab_type": "text" + }, + "source": [ + "5. Implement a function `cumulative_sum(lst)` that takes a list of numbers and returns a list of same size where the element `i` is the sum of the elements `0` to `i` of the input list. For example given `[1,2,3]`, you should return [1,3,6]." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "GX_6TO5dtOUv", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def cumulative_sum(lst):\n", + " csum=0\n", + " new_lst=[]\n", + "\n", + " for i in range(len(lst)):\n", + " if i==0:\n", + " new_lst.append(lst[0])\n", + " else:\n", + " new_lst.append(new_lst[i-1]+lst[i])\n", + "\n", + " return new_lst" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "heby09hitOXV", + "colab_type": "code", + "outputId": "08ca1a3f-2038-41db-9a16-85a3aa4ef241", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "num=[1,2,3]\n", + "cumulative_sum(num)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 3, 6]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 154 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "guii7hqcuh7D", + "colab_type": "code", + "outputId": "ff1e7e15-7ccc-4850-8f4a-82219115b5d2", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "x=[1,2,4,5,6]\n", + "cumulative_sum(x)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[1, 3, 7, 12, 18]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 155 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3pp4Kp21R7M9", + "colab_type": "text" + }, + "source": [ + "6. Imagine you have a normal distributed random variable `x`. For example `x` can be grades on this exam. Using the normal distribution generator and histogram functions from lecture (provided below) and `cumulative_sum` from previous question to compute what is the value of `x_{90}` in $\\sigma$ such that 90% of the values $x$ are below `x_{90}`. In other words:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "1nS_QhaoR7M9", + "colab_type": "text" + }, + "source": [ + "$$\n", + "\\int_{-\\infty}^{x_{90}} N(x;\\mu=0,\\sigma=1) dx = 0.9\n", + "$$" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "-tA7cV2VR7M9", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import math\n", + "import random\n", + "\n", + "def generate_normal(N,m=0,s=1):\n", + " out = list() \n", + " \n", + " while len(out)=bin_edges[i] and d 0:\n", + " return(a_set.intersection(b_set))\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IJDf6ebYdBHV", + "colab_type": "code", + "outputId": "a6436b56-0339-44e7-efb9-8555eb36fc79", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "a = [1,2,5,7,9,10]\n", + "b = [1,3,4,7,8]\n", + "common_elements(a,b)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{1, 7}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 55 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3vA7M9pldBHX", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* Write a function that reads takes a string and returns `True` if the string is a palindrome. (A palindrome is a string that reads the same forwards and backwards.)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ncyMDzp6dBHX", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def pal(w):\n", + " rev_w = reversed(w)\n", + " if list(w)==list(rev_w):\n", + " print(\"The string is a palindrome\")\n", + " else:\n", + " print(\"The string is not a palidrome\")\n", + " \n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "v5cmVQ6MdBHZ", + "colab_type": "code", + "outputId": "bb0b573c-e44d-4e97-946d-3a0743e7cc8f", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "w = 'lool'\n", + "pal(w)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "The string is a palindrome\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fT35xwandBHc", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Write a Rock-Paper-Scissors game function, that takes 2 strings, the inputs of player 1 and player 2, and output 1 or 2 corresponding to which player wins, or 0 if draw.\n", + "\n", + "Implement a Rock-Paper-Scissors game by soliciting input from 2 players, testing with this function, and repeating if there is a draw.\n", + "\n", + "Remember the rules:\n", + "\n", + "* Rock beats scissors\n", + "* Scissors beats paper\n", + "* Paper beats rock" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6HGcQsY8zF3e", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#Write your solution here\n", + "p1score = 0\n", + "p2score = 0\n", + "\n", + "def compare(p1,p2):\n", + " global p1score\n", + " global p2score\n", + "\n", + " if p1==p2:\n", + " return(\"Its a draw\")\n", + " return compare(p1,p2)\n", + " elif p1=='r':\n", + " if p2=='s':\n", + " p1score+=1\n", + " return(\"Rock wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Paper wins, player 2 wins\")\n", + " elif p1=='p':\n", + " if p2=='r':\n", + " p1score+=1\n", + " return(\"Paper wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Scissors wins, player 2 wins\")\n", + " elif p1=='s':\n", + " if p2=='p':\n", + " p1score+=1\n", + " return(\"Scissors wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Rock wins, player 2 wins\")" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "ooR2ldZBdBHf", + "colab_type": "code", + "outputId": "22c16a71-0699-4397-a4f2-e71ecd963afb", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + } + }, + "source": [ + "# Test your solution here\n", + "noWinner = 1\n", + "while noWinner: \n", + " print(\"This is rock, paper, scissors. Best 2 out of 3 wins.\")\n", + " player1=input(\"Player 1, choose rock (r), paper (p), or scissors (s): \")\n", + " player2=input(\"Player 2, choose rock (r), paper (p), or scissors (s): \")\n", + " print(compare(player1, player2))\n", + " print(\"Player1: \"+str(p1score)+\" points\")\n", + " print(\"Player2: \"+str(p2score)+\" points\")\n", + "\n", + " if p1score==2 or p2score==2:\n", + " noWinner = 0" + ], + "execution_count": 44, + "outputs": [ + { + "output_type": "stream", + "text": [ + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): s\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Its a draw\n", + "Player1: 0 points\n", + "Player2: 0 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): r\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Rock wins, player 1 wins\n", + "Player1: 1 points\n", + "Player2: 0 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): p\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Scissors wins, player 2 wins\n", + "Player1: 1 points\n", + "Player2: 1 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): r\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Rock wins, player 1 wins\n", + "Player1: 2 points\n", + "Player2: 1 points\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dJQzXNKzdBHh", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Write a function that takes a integer `n` as input and \n", + "outputs a list of the first `n` Fibonnaci numbers.\n", + "\n", + "The Fibonnaci seqence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, …)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "G_4ooRXTdBHh", + "colab_type": "code", + "outputId": "9a435058-169c-4f1e-a493-aded562c06ad", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "# Write you solution here\n", + "def fibseq(n):\n", + " if n <=1:\n", + " return n\n", + " else:\n", + " return(fibseq(n-1)+fibseq(n-2))\n", + "nn = int(input(\"How many terms?\"))\n", + "if nn <=0:\n", + " print(\"Invalid input, enter positive integer\")\n", + "else:\n", + " print(\"Fibonacci sequence: \")\n", + " for i in range(nn):\n", + " print(fibseq(i))\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "How many terms?7\n", + "Fibonacci sequence: \n", + "0\n", + "1\n", + "1\n", + "2\n", + "3\n", + "5\n", + "8\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "rzK5FskJdBHj", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q6c_AskadBHl", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Write a function that takes a string of consisting of several words and returns a string that reverses the order of the words.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "aJdXX6FHdBHl", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def revwords(s):\n", + " r = s.split()\n", + " r.reverse()\n", + " end=\" \".join(r)\n", + " return end\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nQyhnLZ_dBHn", + "colab_type": "code", + "outputId": "95b49c24-4ebe-4354-eaef-adc44f909cf7", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "s = \"the sky is blue\"\n", + "revwords(s)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'blue is sky the'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 64 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NFSmRaSydBHq", + "colab_type": "text" + }, + "source": [ + "*Exercise 10:* Write a guessing game program that will repeatedly guess a number that the users picks, with the user indicating higher or lower, until it correctly guesses the number." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Ie2E1JzCdBHr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "import random\n", + "def comp_guess():\n", + " high=100\n", + " low=1\n", + " guesses = []\n", + " user_num=int(input(\"Choose a number 1-100 for the computer to guess: \"))\n", + "\n", + " while True:\n", + " compg=random.randint(low, high)\n", + " if compg in guesses:\n", + " compg = random.randint(low,high)\n", + " continue\n", + " if compg > user_num:\n", + " high=compg\n", + " guesses.append(compg)\n", + " print(str(compg)+\" is too high\")\n", + " elif compg" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 15 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "kOJ9dpeWMSSQ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-1/Copy_of_Lab_1.ipynb b/Labs/Lab-1/Copy_of_Lab_1.ipynb new file mode 100644 index 0000000..24702d4 --- /dev/null +++ b/Labs/Lab-1/Copy_of_Lab_1.ipynb @@ -0,0 +1,2121 @@ +{ + "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": "wJuFIPY71ZrP", + "colab_type": "code", + "outputId": "e1b11a80-a161-42ee-cf39-bce154a827ab", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + } + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "FVt_1hPt1dAK", + "colab_type": "text" + }, + "source": [ + "## Notebooks in Colab\n", + "\n", + "You now are presumably in Colab. Word of caution, by default, Google Colab does not save your notebooks, so if you close your session, you will loose your work.\n", + "\n", + "So first thing: from the file menu above select \"Save a copy in Drive\"." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "x0JBL_RFrDDj", + "colab_type": "text" + }, + "source": [ + "## Storing Notebooks in Google Drive\n", + "A better way to work is to save your notebooks directly into Google Drive and upload directly to Git (where you will be downloading and uploading your homework). In order properly setup Git, we'll need to work more directly in your Google Drive.\n", + "\n", + "On the left sidebar, press the file icon to see a listing of files accessibile to this Notebook. Then press \"Mount Drive\" and follow the instructions to mount your Google Drive in this notebook. A new cell will be inserted into this notebook, which after you run by pressing the play button will instruct you to follow a link to log into your Google Account and enable access to your Drive in another tab. Finally you will copy a link from the new tab back into the cell in this notebook. Once you are done, press refresh under files in the left sidebar and you should have \"drive/My Drive\" appear." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "hwJ6wJk3tiLv", + "colab_type": "text" + }, + "source": [ + "## Github\n", + "All the class material will be stored on github. You will also submit your homework using github. To do so, you will need a github account.\n", + "\n", + "If you do not already have a github account or wish to create a new one for this course, create one:\n", + "* Browse to [github.com](https://github.com).\n", + "* Click the green “Sign up for GitHub”\tbutton.\n", + "* Follow instructions for creating an account.\n", + "* Make sure you remember your github username and password.\n", + "\n", + "Write an email to the course TA titled \"Data 1401: Github account\" with your github username (not your password) as the contents.\n", + "\n", + "## Google Groups\n", + "\n", + "Class annoucements will be made via google groups. If you did not already receive an invite to the class google group, had trouble with the invite, or wish to use a different email address, write an email to the course TA titled \"Data 1401: Google Group\" with your preferred email.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "TjfIzdQZqvzk", + "colab_type": "text" + }, + "source": [ + "## Introduction: Unix, Git, and Jupyter\n", + "\n", + "This lab aims to introduce you to basic Unix, familiarize you with iPython notebooks and get you setup to submit your homework.\n", + "*italicized text*" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "C_LmOgzFqvzp", + "colab_type": "text" + }, + "source": [ + "\n", + "\n", + "### Terminal, Shell, and ssh\n", + "\n", + "\n", + "The terminal is a simple program that generally runs another program, taking mostly keyboard input from you, passing it to this other program, and taking the output of the program and displaying on the screen for you.\n", + "\n", + "The terminal usually runs a program called a shell. Shells present a command prompt where you can type in commands, which are then executed when you press enter. In most shells, there are some special commands which the shell will execute. Everything else you type in, the shell will assume is a name of a program you want to run and arguments you want to pass that program. So if the shell doesn't recognize something you type in, it'll try to find a program with a name that is the same as the first word you gave it. \n", + "\n", + "### Shell in Colab\n", + "\n", + "Unfortunately, google Colab does not allow you to open a terminal window. Jupyter does, so if you are running in Jupyter (which most of you will not be), you may choose to open a terminal window by returning to the jupyter file list tab and selecting new terminal from the top right.\n", + "\n", + "For Colab, we will have to do something non-ideal, but functional. There are several ways to execute shell commands from within a python notebook. For example, you can use any shell command by putting \"!\" in front of the command:\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "KJ5f-WO0wcAv", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!ls\n", + "!echo \"----------\"\n", + "!ls sample_data" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "source": [ + "!echo \"Technique 1:\"\n", + "!ls\n", + "!cd sample_data\n", + "!ls" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "2-Znf97Lxl-Z", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!echo \"Technique 2:\"\n", + "!ls ; cd sample_data ;ls" + ], + "execution_count": 0, + "outputs": [] + }, + { + "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": {} + }, + "source": [ + "!echo \"Technique 3:\"\n", + "!ls \n", + "%cd sample_data \n", + "!ls" + ], + "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": "code", + "metadata": { + "id": "MIDFitLZyuZy", + "colab_type": "code", + "outputId": "67f17d93-ed37-477b-e07b-a84ad94f182d", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "!/bin/bash --noediting\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# ls\n", + "\u001b[0m\u001b[01;34mdrive\u001b[0m favoritecolors \u001b[01;34msample_data\u001b[0m sorted_favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd sample_data\n", + "\u001b]0;root@47551fbb9a44: /content/sample_data\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# pwd\n", + "/content/sample_data\n", + "\u001b]0;root@47551fbb9a44: /content/sample_data\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q-4hfZBywW25", + "colab_type": "text" + }, + "source": [ + "While in this instance your shell is running in a this notebook, you can also run terminals natively on your own computer. On Linux or MacOS, you just have to run a program called terminal. In Windows you can start a \"command prompt\". \n", + "\n", + "\n", + "Type in \"ls\" into the terminal and press enter. The shell will find a program called \"ls\", a standard tool in Unix, and run it. \"ls\" lists the contents (files and directories) of your current directory. If you are just starting in this course, you probably only see the git repository you cloned. \n", + "\n", + "A subtle point to realize here is that while the terminal is running in the browser that is running on the computer in front of you, the shell is actually running on a machine on google hardware. The shell prompt typically displays the name of the machine you are using. What you are not seeing is that there is an intermidate program between the terminal running on your computer and the shell running on google. This intermidary program is taking your input from the terminal sending it over the network to google and bringing back the responses for you terminal to display.\n", + "\n", + "A bit of extra information. If you start a terminal on your own computer, the shell runs locally. The \"ls\" command would then list contents of a directory on your computer. You can typically connect to Unix computers by evoking a shell running on that machine over the network. In this case, you would have to initiate this intermidiary program yourself. The program is called \"ssh\" (secure shell). You can \"ssh\" to another machine from your machine, by simply typing \"ssh\" followed by the machine name or IP address. Most likely you would be prompted for a password, after which you would dropped into the prompt of a shell running on the remote machine. \n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "51Eya4LBqvzs", + "colab_type": "text" + }, + "source": [ + "## Programs and Environment Variables\n", + "\n", + "You have a listing of your current directory, but you don't know where that directory resides. You can see what directory you are using the command \"pwd\" (print working directory). Issue the command and look at the response. You'll get a slash (\"/\") separated list, known as the path, of the directory hierarchy of your current working directory. On Colab, this will start with \"contents\"\n", + "\n", + "Now back to thinking about the command prompt. Since \"ls\" is a program, it most be stored somewhere. It is clearly not in your working directory, because you didn't see it when you executed \"ls\". We can ask the shell to tell us where it found \"ls\" using the \"which ls\" command. Note that \"which\" is also a program. \"which ls\" comes back with \"/bin/ls\", telling you the \"ls\" program is sitting in \"/bin\" directory of the system. \n", + "\n", + "Lets see what else is in there by issuing a \"ls /bin\" command. You will get a long list of programs. You can run any of these programs by just typing their names and pressing enter. You may be able to guess what some of these programs do, but if you want to know, most of them provide you help, using \"--help\" or \"-h\" flag. For example execute \"ls --help\". For more information about a program or command, you can use Unix's manual pages using the \"man\" command. Try typing \"man ls\". Note that you will need to press space to scroll through lengthy manual pages and \"q\" to exit back to the shell prompt. \n", + "\n", + "Another command interesting is \"echo\". \"echo\" simply prints whatever you put after it to the screen. Try executing \"echo Hello World.\"\n", + "\n", + "At this point, you may wonder how was it that the shell knew to look for programs in \"/bin\"? The shell keeps a list of places to look for programs an environment variable with the name \"PATH\". The shell keeps a table that map string variable names to string expressions. When the shell starts, its configuration files set some environment variables that it uses. You can see the full list of defined environment variables using the command \"printenv\".\n", + "\n", + "You can use a environment variable in a shell by prepending name of the variable with a dollar sign character (\"\\$\"). So you can print out the PATH environment variable using the command \"echo $PATH\". What you will see is a colon (\":\") separated list of directories that the shell will search (in order) whenever you type in anything.\n", + "\n", + "You can set you own environment variables. Different shells have different syntax. Lets first figure out what shell we are running. \n", + "\n", + "*Exercise 1:* Use the \"echo\" command to print out the value of the \"SHELL\" environment variable:" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YS7YFiPwqvzu", + "colab_type": "text" + }, + "source": [ + "!/bin/bash --noediting" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "vkQmmbcjsdPx", + "colab_type": "code", + "outputId": "eeaf6893-38ab-4569-a21a-60b01016f665", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (123): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# pwd\n", + "/content\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# which ls\n", + "/bin/ls\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls/bin\n", + "bash: ls/bin: No such file or directory\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /bin\n", + "\u001b[0m\u001b[01;32mbash\u001b[0m \u001b[01;32mjournalctl\u001b[0m \u001b[01;32msync\u001b[0m\n", + "\u001b[01;32mbunzip2\u001b[0m \u001b[01;32mkill\u001b[0m \u001b[01;32msystemctl\u001b[0m\n", + "\u001b[01;32mbzcat\u001b[0m \u001b[01;32mkmod\u001b[0m \u001b[01;36msystemd\u001b[0m\n", + "\u001b[01;36mbzcmp\u001b[0m \u001b[01;32mless\u001b[0m \u001b[01;32msystemd-ask-password\u001b[0m\n", + "\u001b[01;32mbzdiff\u001b[0m \u001b[01;32mlessecho\u001b[0m \u001b[01;32msystemd-escape\u001b[0m\n", + "\u001b[01;36mbzegrep\u001b[0m \u001b[01;36mlessfile\u001b[0m \u001b[01;32msystemd-hwdb\u001b[0m\n", + "\u001b[01;32mbzexe\u001b[0m \u001b[01;32mlesskey\u001b[0m \u001b[01;32msystemd-inhibit\u001b[0m\n", + "\u001b[01;36mbzfgrep\u001b[0m \u001b[01;32mlesspipe\u001b[0m \u001b[01;32msystemd-machine-id-setup\u001b[0m\n", + "\u001b[01;32mbzgrep\u001b[0m \u001b[01;32mln\u001b[0m \u001b[01;32msystemd-notify\u001b[0m\n", + "\u001b[01;32mbzip2\u001b[0m \u001b[01;32mlogin\u001b[0m \u001b[01;32msystemd-sysusers\u001b[0m\n", + "\u001b[01;32mbzip2recover\u001b[0m \u001b[01;32mloginctl\u001b[0m \u001b[01;32msystemd-tmpfiles\u001b[0m\n", + "\u001b[01;36mbzless\u001b[0m \u001b[01;32mls\u001b[0m \u001b[01;32msystemd-tty-ask-password-agent\u001b[0m\n", + "\u001b[01;32mbzmore\u001b[0m \u001b[01;32mlsblk\u001b[0m \u001b[01;32mtar\u001b[0m\n", + "\u001b[01;32mcat\u001b[0m \u001b[01;36mlsmod\u001b[0m \u001b[01;32mtempfile\u001b[0m\n", + "\u001b[01;32mchgrp\u001b[0m \u001b[01;32mmkdir\u001b[0m \u001b[01;32mtouch\u001b[0m\n", + "\u001b[01;32mchmod\u001b[0m \u001b[01;32mmknod\u001b[0m \u001b[01;32mtrue\u001b[0m\n", + "\u001b[01;32mchown\u001b[0m \u001b[01;32mmktemp\u001b[0m \u001b[01;32mudevadm\u001b[0m\n", + "\u001b[01;32mcp\u001b[0m \u001b[01;32mmore\u001b[0m \u001b[01;32mulockmgr_server\u001b[0m\n", + "\u001b[01;32mdash\u001b[0m \u001b[37;41mmount\u001b[0m \u001b[37;41mumount\u001b[0m\n", + "\u001b[01;32mdate\u001b[0m \u001b[01;32mmountpoint\u001b[0m \u001b[01;32muname\u001b[0m\n", + "\u001b[01;32mdd\u001b[0m \u001b[01;32mmv\u001b[0m \u001b[01;32muncompress\u001b[0m\n", + "\u001b[01;32mdf\u001b[0m \u001b[01;32mnetworkctl\u001b[0m \u001b[01;32mvdir\u001b[0m\n", + "\u001b[01;32mdir\u001b[0m \u001b[01;36mnisdomainname\u001b[0m \u001b[01;32mwdctl\u001b[0m\n", + "\u001b[01;32mdmesg\u001b[0m \u001b[01;36mpidof\u001b[0m \u001b[01;32mwhich\u001b[0m\n", + "\u001b[01;36mdnsdomainname\u001b[0m \u001b[01;32mps\u001b[0m \u001b[01;36mypdomainname\u001b[0m\n", + "\u001b[01;36mdomainname\u001b[0m \u001b[01;32mpwd\u001b[0m \u001b[01;32mzcat\u001b[0m\n", + "\u001b[01;32mecho\u001b[0m \u001b[01;36mrbash\u001b[0m \u001b[01;32mzcmp\u001b[0m\n", + "\u001b[01;32megrep\u001b[0m \u001b[01;32mreadlink\u001b[0m \u001b[01;32mzdiff\u001b[0m\n", + "\u001b[01;32mfalse\u001b[0m \u001b[01;32mrm\u001b[0m \u001b[01;32mzegrep\u001b[0m\n", + "\u001b[01;32mfgrep\u001b[0m \u001b[01;32mrmdir\u001b[0m \u001b[01;32mzfgrep\u001b[0m\n", + "\u001b[01;32mfindmnt\u001b[0m \u001b[01;32mrun-parts\u001b[0m \u001b[01;32mzforce\u001b[0m\n", + "\u001b[37;41mfusermount\u001b[0m \u001b[01;32msed\u001b[0m \u001b[01;32mzgrep\u001b[0m\n", + "\u001b[01;32mgrep\u001b[0m \u001b[01;36msh\u001b[0m \u001b[01;32mzless\u001b[0m\n", + "\u001b[01;32mgunzip\u001b[0m \u001b[01;36msh.distrib\u001b[0m \u001b[01;32mzmore\u001b[0m\n", + "\u001b[01;32mgzexe\u001b[0m \u001b[01;32msleep\u001b[0m \u001b[01;32mznew\u001b[0m\n", + "\u001b[01;32mgzip\u001b[0m \u001b[01;32mstty\u001b[0m\n", + "\u001b[01;32mhostname\u001b[0m \u001b[37;41msu\u001b[0m\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# ls --help\n", + "Usage: ls [OPTION]... [FILE]...\n", + "List information about the FILEs (the current directory by default).\n", + "Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.\n", + "\n", + "Mandatory arguments to long options are mandatory for short options too.\n", + " -a, --all do not ignore entries starting with .\n", + " -A, --almost-all do not list implied . and ..\n", + " --author with -l, print the author of each file\n", + " -b, --escape print C-style escapes for nongraphic characters\n", + " --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\n", + " '--block-size=M' prints sizes in units of\n", + " 1,048,576 bytes; see SIZE format below\n", + " -B, --ignore-backups do not list implied entries ending with ~\n", + " -c with -lt: sort by, and show, ctime (time of last\n", + " modification of file status information);\n", + " with -l: show ctime and sort by name;\n", + " otherwise: sort by ctime, newest first\n", + " -C list entries by columns\n", + " --color[=WHEN] colorize the output; WHEN can be 'always' (default\n", + " if omitted), 'auto', or 'never'; more info below\n", + " -d, --directory list directories themselves, not their contents\n", + " -D, --dired generate output designed for Emacs' dired mode\n", + " -f do not sort, enable -aU, disable -ls --color\n", + " -F, --classify append indicator (one of */=>@|) to entries\n", + " --file-type likewise, except do not append '*'\n", + " --format=WORD across -x, commas -m, horizontal -x, long -l,\n", + " single-column -1, verbose -l, vertical -C\n", + " --full-time like -l --time-style=full-iso\n", + " -g like -l, but do not list owner\n", + " --group-directories-first\n", + " group directories before files;\n", + " can be augmented with a --sort option, but any\n", + " use of --sort=none (-U) disables grouping\n", + " -G, --no-group in a long listing, don't print group names\n", + " -h, --human-readable with -l and/or -s, print human readable sizes\n", + " (e.g., 1K 234M 2G)\n", + " --si likewise, but use powers of 1000 not 1024\n", + " -H, --dereference-command-line\n", + " follow symbolic links listed on the command line\n", + " --dereference-command-line-symlink-to-dir\n", + " follow each command line symbolic link\n", + " that points to a directory\n", + " --hide=PATTERN do not list implied entries matching shell PATTERN\n", + " (overridden by -a or -A)\n", + " --hyperlink[=WHEN] hyperlink file names; WHEN can be 'always'\n", + " (default if omitted), 'auto', or 'never'\n", + " --indicator-style=WORD append indicator with style WORD to entry names:\n", + " none (default), slash (-p),\n", + " file-type (--file-type), classify (-F)\n", + " -i, --inode print the index number of each file\n", + " -I, --ignore=PATTERN do not list implied entries matching shell PATTERN\n", + " -k, --kibibytes default to 1024-byte blocks for disk usage\n", + " -l use a long listing format\n", + " -L, --dereference when showing file information for a symbolic\n", + " link, show information for the file the link\n", + " references rather than for the link itself\n", + " -m fill width with a comma separated list of entries\n", + " -n, --numeric-uid-gid like -l, but list numeric user and group IDs\n", + " -N, --literal print entry names without quoting\n", + " -o like -l, but do not list group information\n", + " -p, --indicator-style=slash\n", + " append / indicator to directories\n", + " -q, --hide-control-chars print ? instead of nongraphic characters\n", + " --show-control-chars show nongraphic characters as-is (the default,\n", + " unless program is 'ls' and output is a terminal)\n", + " -Q, --quote-name enclose entry names in double quotes\n", + " --quoting-style=WORD use quoting style WORD for entry names:\n", + " literal, locale, shell, shell-always,\n", + " shell-escape, shell-escape-always, c, escape\n", + " -r, --reverse reverse order while sorting\n", + " -R, --recursive list subdirectories recursively\n", + " -s, --size print the allocated size of each file, in blocks\n", + " -S sort by file size, largest first\n", + " --sort=WORD sort by WORD instead of name: none (-U), size (-S),\n", + " time (-t), version (-v), extension (-X)\n", + " --time=WORD with -l, show time as WORD instead of default\n", + " modification time: atime or access or use (-u);\n", + " ctime or status (-c); also use specified time\n", + " as sort key if --sort=time (newest first)\n", + " --time-style=STYLE with -l, show times using style STYLE:\n", + " full-iso, long-iso, iso, locale, or +FORMAT;\n", + " FORMAT is interpreted like in 'date'; if FORMAT\n", + " is FORMAT1FORMAT2, then FORMAT1 applies\n", + " to non-recent files and FORMAT2 to recent files;\n", + " if STYLE is prefixed with 'posix-', STYLE\n", + " takes effect only outside the POSIX locale\n", + " -t sort by modification time, newest first\n", + " -T, --tabsize=COLS assume tab stops at each COLS instead of 8\n", + " -u with -lt: sort by, and show, access time;\n", + " with -l: show access time and sort by name;\n", + " otherwise: sort by access time, newest first\n", + " -U do not sort; list entries in directory order\n", + " -v natural sort of (version) numbers within text\n", + " -w, --width=COLS set output width to COLS. 0 means no limit\n", + " -x list entries by lines instead of by columns\n", + " -X sort alphabetically by entry extension\n", + " -Z, --context print any security context of each file\n", + " -1 list one file per line. Avoid '\\n' with -q or -b\n", + " --help display this help and exit\n", + " --version output version information and exit\n", + "\n", + "The SIZE argument is an integer and optional unit (example: 10K is 10*1024).\n", + "Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).\n", + "\n", + "Using color to distinguish file types is disabled both by default and\n", + "with --color=never. With --color=auto, ls emits color codes only when\n", + "standard output is connected to a terminal. The LS_COLORS environment\n", + "variable can change the settings. Use the dircolors command to set it.\n", + "\n", + "Exit status:\n", + " 0 if OK,\n", + " 1 if minor problems (e.g., cannot access subdirectory),\n", + " 2 if serious trouble (e.g., cannot access command-line argument).\n", + "\n", + "GNU coreutils online help: \n", + "Full documentation at: \n", + "or available locally via: info '(coreutils) ls invocation'\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# man ls\n", + "LS(1POSIX) POSIX Programmer's Manual LS(1POSIX)\n", + "\n", + "P\bPR\bRO\bOL\bLO\bOG\bG\n", + " This manual page is part of the POSIX Programmer's Manual. The Linux\n", + " implementation of this interface may differ (consult the corresponding\n", + " Linux manual page for details of Linux behavior), or the interface may\n", + " not be implemented on Linux.\n", + "\n", + "N\bNA\bAM\bME\bE\n", + " ls — list directory contents\n", + "\n", + "S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS\n", + " ls [\b[−ikqrs]\b] [\b[−glno]\b] [\b[−A|−a]\b] [\b[−C|−m|−x|−1]\b] \\\n", + " [\b[−F|−p]\b] [\b[−H|−L]\b] [\b[−R|−d]\b] [\b[−S|−f|−t]\b] [\b[−c|−u]\b] [\b[_\bf_\bi_\bl_\be...]\b]\n", + "\n", + "D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\n", + " For each operand that names a file of a type other than directory or\n", + " symbolic link to a directory, _\bl_\bs shall write the name of the file as\n", + " well as any requested, associated information. For each operand that\n", + " names a file of type directory, _\bl_\bs shall write the names of files con‐\n", + " tained within the directory as well as any requested, associated infor‐\n", + " mation. Filenames beginning with a ('\b'.\b.'\b') and any associated\n", + " information shall not be written out unless explicitly referenced, the\n", + " −\b−A\bA or −\b−a\ba option is supplied, or an implementation-defined condition\n", + " causes them to be written. If one or more of the −\b−d\bd, −\b−F\bF, or −\b−l\bl options\n", + " are specified, and neither the −\b−H\bH nor the −\b−L\bL option is specified, for\n", + " each operand that names a file of type symbolic link to a directory, _\bl_\bs\n", + " shall write the name of the file as well as any requested, associated\n", + " information. If none of the −\b−d\bd, −\b−F\bF, or −\b−l\bl options are specified, or the\n", + " −\b−H\bH or −\b−L\bL options are specified, for each operand that names a file of\n", + " type symbolic link to a directory, _\bl_\bs shall write the names of files\n", + " contained within the directory as well as any requested, associated\n", + " information. In each case where the names of files contained within a\n", + " directory are written, if the directory contains any symbolic links\n", + " then _\bl_\bs shall evaluate the file information and file type to be those\n", + " of the symbolic link itself, unless the −\b−L\bL option is specified.\n", + "\n", + " If no operands are specified, _\bl_\bs shall behave as if a single operand of\n", + " dot ('\b'.\b.'\b') had been specified. If more than one operand is specified,\n", + " _\bl_\bs shall write non-directory operands first; it shall sort directory\n", + " and non-directory operands separately according to the collating\n", + " sequence in the current locale.\n", + "\n", + " The _\bl_\bs utility shall detect infinite loops; that is, entering a previ‐\n", + " ously visited directory that is an ancestor of the last file encoun‐\n", + " tered. When it detects an infinite loop, _\bl_\bs shall write a diagnostic\n", + " message to standard error and shall either recover its position in the\n", + " hierarchy or terminate.\n", + "\n", + "O\bOP\bPT\bTI\bIO\bON\bNS\bS\n", + " The _\bl_\bs utility shall conform to the Base Definitions volume of\n", + " POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b1_\b2_\b._\b2, _\bU_\bt_\bi_\bl_\bi_\bt_\by _\bS_\by_\bn_\bt_\ba_\bx _\bG_\bu_\bi_\bd_\be_\bl_\bi_\bn_\be_\bs.\n", + "\n", + " The following options shall be supported:\n", + "\n", + " −\b−A\bA Write out all directory entries, including those whose names\n", + " begin with a ('\b'.\b.'\b') but excluding the entries dot\n", + " and dot-dot (if they exist).\n", + "\n", + " −\b−C\bC Write multi-text-column output with entries sorted down the\n", + " columns, according to the collating sequence. The number of\n", + " text columns and the column separator characters are unspeci‐\n", + " fied, but should be adapted to the nature of the output\n", + " device. This option disables long format output.\n", + "\n", + " −\b−F\bF Do not follow symbolic links named as operands unless the −\b−H\bH\n", + " or −\b−L\bL options are specified. Write a ('\b'/\b/'\b') immedi‐\n", + " ately after each pathname that is a directory, an \n", + " ('\b'*\b*'\b') after each that is executable, a ('\b'|\b|'\b')\n", + " after each that is a FIFO, and an at-sign ('\b'@\b@'\b') after each\n", + " that is a symbolic link. For other file types, other symbols\n", + " may be written.\n", + "\n", + " −\b−H\bH Evaluate the file information and file type for symbolic\n", + " links specified on the command line to be those of the file\n", + " referenced by the link, and not the link itself; however, _\bl_\bs\n", + " shall write the name of the link itself and not the file ref‐\n", + " erenced by the link.\n", + "\n", + " −\b−L\bL Evaluate the file information and file type for all symbolic\n", + " links (whether named on the command line or encountered in a\n", + " file hierarchy) to be those of the file referenced by the\n", + " link, and not the link itself; however, _\bl_\bs shall write the\n", + " name of the link itself and not the file referenced by the\n", + " link. When −\b−L\bL is used with −\b−l\bl, write the contents of symbolic\n", + " links in the long format (see the STDOUT section).\n", + "\n", + " −\b−R\bR Recursively list subdirectories encountered. When a symbolic\n", + " link to a directory is encountered, the directory shall not\n", + " be recursively listed unless the −\b−L\bL option is specified. The\n", + " use of −\b−R\bR with −\b−d\bd or −\b−f\bf produces unspecified results.\n", + "\n", + " −\b−S\bS Sort with the primary key being file size (in decreasing\n", + " order) and the secondary key being filename in the collating\n", + " sequence (in increasing order).\n", + "\n", + " −\b−a\ba Write out all directory entries, including those whose names\n", + " begin with a ('\b'.\b.'\b').\n", + "\n", + " −\b−c\bc Use time of last modification of the file status information\n", + " (see the Base Definitions volume of POSIX.1‐2008,\n", + " <\b\b>) instead of last modification of the file itself\n", + " for sorting (−\b−t\bt) or writing (−\b−l\bl).\n", + "\n", + " −\b−d\bd Do not follow symbolic links named as operands unless the −\b−H\bH\n", + " or −\b−L\bL options are specified. Do not treat directories differ‐\n", + " ently than other types of files. The use of −\b−d\bd with −\b−R\bR or −\b−f\bf\n", + " produces unspecified results.\n", + "\n", + " −\b−f\bf List the entries in directory operands in the order they\n", + " appear in the directory. The behavior for non-directory oper‐\n", + " ands is unspecified. This option shall turn on −\b−a\ba. When −\b−f\bf\n", + " is specified, any occurrences of the −\b−r\br, −\b−S\bS, and −\b−t\bt options\n", + " shall be ignored and any occurrences of the −\b−A\bA, −\b−g\bg, −\b−l\bl, −\b−n\bn,\n", + " −\b−o\bo, and −\b−s\bs options may be ignored. The use of −\b−f\bf with −\b−R\bR or\n", + " −\b−d\bd produces unspecified results.\n", + "\n", + " −\b−g\bg Turn on the −\b−l\bl (ell) option, but disable writing the file's\n", + " owner name or number. Disable the −\b−C\bC, −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−i\bi For each file, write the file's file serial number (see\n", + " _\bs_\bt_\ba_\bt() in the System Interfaces volume of POSIX.1‐2008).\n", + "\n", + " −\b−k\bk Set the block size for the −\b−s\bs option and the per-directory\n", + " block count written for the −\b−l\bl, −\b−n\bn, −\b−s\bs, −\b−g\bg, and −\b−o\bo options\n", + " (see the STDOUT section) to 1024 bytes.\n", + "\n", + " −\b−l\bl (The letter ell.) Do not follow symbolic links named as oper‐\n", + " ands unless the −\b−H\bH or −\b−L\bL options are specified. Write out in\n", + " long format (see the STDOUT section). Disable the −\b−C\bC, −\b−m\bm, and\n", + " −\b−x\bx options.\n", + "\n", + " −\b−m\bm Stream output format; list pathnames across the page, sepa‐\n", + " rated by a character followed by a character.\n", + " Use a character as the list terminator and after\n", + " the separator sequence when there is not room on a line for\n", + " the next list entry. This option disables long format output.\n", + "\n", + " −\b−n\bn Turn on the −\b−l\bl (ell) option, but when writing the file's\n", + " owner or group, write the file's numeric UID or GID rather\n", + " than the user or group name, respectively. Disable the −\b−C\bC,\n", + " −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−o\bo Turn on the −\b−l\bl (ell) option, but disable writing the file's\n", + " group name or number. Disable the −\b−C\bC, −\b−m\bm, and −\b−x\bx options.\n", + "\n", + " −\b−p\bp Write a ('\b'/\b/'\b') after each filename if that file is a\n", + " directory.\n", + "\n", + " −\b−q\bq Force each instance of non-printable filename characters and\n", + " characters to be written as the ('\b'?\b?'\b')\n", + " character. Implementations may provide this option by default\n", + " if the output is to a terminal device.\n", + "\n", + " −\b−r\br Reverse the order of the sort to get reverse collating\n", + " sequence oldest first, or smallest file size first depending\n", + " on the other options given.\n", + "\n", + " −\b−s\bs Indicate the total number of file system blocks consumed by\n", + " each file displayed. If the −\b−k\bk option is also specified, the\n", + " block size shall be 1024 bytes; otherwise, the block size is\n", + " implementation-defined.\n", + "\n", + " −\b−t\bt Sort with the primary key being time modified (most recently\n", + " modified first) and the secondary key being filename in the\n", + " collating sequence. For a symbolic link, the time used as\n", + " the sort key is that of the symbolic link itself, unless _\bl_\bs\n", + " is evaluating its file information to be that of the file\n", + " referenced by the link (see the −\b−H\bH and −\b−L\bL options).\n", + "\n", + " −\b−u\bu Use time of last access (see the Base Definitions volume of\n", + " POSIX.1‐2008, <\b\b>) instead of last modification of\n", + " the file for sorting (−\b−t\bt) or writing (−\b−l\bl).\n", + "\n", + " −\b−x\bx The same as −\b−C\bC, except that the multi-text-column output is\n", + " produced with entries sorted across, rather than down, the\n", + " columns. This option disables long format output.\n", + "\n", + " −\b−1\b1 (The numeric digit one.) Force output to be one entry per\n", + " line. This option does not disable long format output. (Long\n", + " format output is enabled by −\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo; and\n", + " disabled by −\b−C\bC, −\b−m\bm, and −\b−x\bx.)\n", + "\n", + " If an option that enables long format output (−\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo\n", + " is given with an option that disables long format output (−\b−C\bC, −\b−m\bm, and\n", + " −\b−x\bx), this shall not be considered an error. The last of these options\n", + " specified shall determine whether long format output is written.\n", + "\n", + " If −\b−R\bR, −\b−d\bd, or −\b−f\bf are specified, the results of specifying these mutu‐\n", + " ally-exclusive options are specified by the descriptions of these\n", + " options above. If more than one of any of the other options shown in\n", + " the SYNOPSIS section in mutually-exclusive sets are given, this shall\n", + " not be considered an error; the last option specified in each set shall\n", + " determine the output.\n", + "\n", + " Note that if −\b−t\bt is specified, −\b−c\bc and −\b−u\bu are not only mutually-exclusive\n", + " with each other, they are also mutually-exclusive with −\b−S\bS when deter‐\n", + " mining sort order. But even if −\b−S\bS is specified after all occurrences of\n", + " −\b−c\bc, −\b−t\bt, and −\b−u\bu, the last use of −\b−c\bc or −\b−u\bu determines the timestamp\n", + " printed when producing long format output.\n", + "\n", + "O\bOP\bPE\bER\bRA\bAN\bND\bDS\bS\n", + " The following operand shall be supported:\n", + "\n", + " _\bf_\bi_\bl_\be A pathname of a file to be written. If the file specified is\n", + " not found, a diagnostic message shall be output on standard\n", + " error.\n", + "\n", + "S\bST\bTD\bDI\bIN\bN\n", + " Not used.\n", + "\n", + "I\bIN\bNP\bPU\bUT\bT F\bFI\bIL\bLE\bES\bS\n", + " None.\n", + "\n", + "E\bEN\bNV\bVI\bIR\bRO\bON\bNM\bME\bEN\bNT\bT V\bVA\bAR\bRI\bIA\bAB\bBL\bLE\bES\bS\n", + " The following environment variables shall affect the execution of _\bl_\bs:\n", + "\n", + " _\bC_\bO_\bL_\bU_\bM_\bN_\bS Determine the user's preferred column position width for\n", + " writing multiple text-column output. If this variable con‐\n", + " tains a string representing a decimal integer, the _\bl_\bs utility\n", + " shall calculate how many pathname text columns to write (see\n", + " −\b−C\bC) based on the width provided. If _\bC_\bO_\bL_\bU_\bM_\bN_\bS is not set or\n", + " invalid, an implementation-defined number of column positions\n", + " shall be assumed, based on the implementation's knowledge of\n", + " the output device. The column width chosen to write the names\n", + " of files in any given directory shall be constant. Filenames\n", + " shall not be truncated to fit into the multiple text-column\n", + " output.\n", + "\n", + " _\bL_\bA_\bN_\bG Provide a default value for the internationalization vari‐\n", + " ables that are unset or null. (See the Base Definitions vol‐\n", + " ume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b8_\b._\b2, _\bI_\bn_\bt_\be_\br_\bn_\ba_\bt_\bi_\bo_\bn_\ba_\bl_\bi_\bz_\ba_\bt_\bi_\bo_\bn _\bV_\ba_\br_\bi_\b‐\n", + " _\ba_\bb_\bl_\be_\bs for the precedence of internationalization variables\n", + " used to determine the values of locale categories.)\n", + "\n", + " _\bL_\bC_\b__\bA_\bL_\bL If set to a non-empty string value, override the values of\n", + " all the other internationalization variables.\n", + "\n", + " _\bL_\bC_\b__\bC_\bO_\bL_\bL_\bA_\bT_\bE\n", + " Determine the locale for character collation information in\n", + " determining the pathname collation sequence.\n", + "\n", + " _\bL_\bC_\b__\bC_\bT_\bY_\bP_\bE Determine the locale for the interpretation of sequences of\n", + " bytes of text data as characters (for example, single-byte as\n", + " opposed to multi-byte characters in arguments) and which\n", + " characters are defined as printable (character class p\bpr\bri\bin\bnt\bt).\n", + "\n", + " _\bL_\bC_\b__\bM_\bE_\bS_\bS_\bA_\bG_\bE_\bS\n", + " Determine the locale that should be used to affect the format\n", + " and contents of diagnostic messages written to standard\n", + " error.\n", + "\n", + " _\bL_\bC_\b__\bT_\bI_\bM_\bE Determine the format and contents for date and time strings\n", + " written by _\bl_\bs.\n", + "\n", + " _\bN_\bL_\bS_\bP_\bA_\bT_\bH Determine the location of message catalogs for the processing\n", + " of _\bL_\bC_\b__\bM_\bE_\bS_\bS_\bA_\bG_\bE_\bS.\n", + "\n", + " _\bT_\bZ Determine the timezone for date and time strings written by\n", + " _\bl_\bs. If _\bT_\bZ is unset or null, an unspecified default timezone\n", + " shall be used.\n", + "\n", + "A\bAS\bSY\bYN\bNC\bCH\bHR\bRO\bON\bNO\bOU\bUS\bS E\bEV\bVE\bEN\bNT\bTS\bS\n", + " Default.\n", + "\n", + "S\bST\bTD\bDO\bOU\bUT\bT\n", + " The default format shall be to list one entry per line to standard out‐\n", + " put; the exceptions are to terminals or when one of the −\b−C\bC, −\b−m\bm, or −\b−x\bx\n", + " options is specified. If the output is to a terminal, the format is\n", + " implementation-defined.\n", + "\n", + " When −\b−m\bm is specified, the format used for the last element of the list\n", + " shall be:\n", + "\n", + " \"\b\"%\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be_\bn_\ba_\bm_\be>\n", + "\n", + " The format used for each other element of the list shall be:\n", + "\n", + " \"\b\"%\b%s\bs,\b,%\b%s\bs\"\b\",\b, <\b<_\bf_\bi_\bl_\be_\bn_\ba_\bm_\be>, <_\bs_\be_\bp_\ba_\br_\ba_\bt_\bo_\br>\n", + "\n", + " where, if there is not room for the next element of the list to fit\n", + " within the current line length, <_\bs_\be_\bp_\ba_\br_\ba_\bt_\bo_\br> is a string containing an\n", + " optional character and a mandatory character; other‐\n", + " wise it is a single character.\n", + "\n", + " If the −\b−i\bi option is specified, the file's file serial number (see the\n", + " Base Definitions volume of POSIX.1‐2008, <\b\b>) shall be written\n", + " in the following format before any other output for the corresponding\n", + " entry:\n", + "\n", + " %\b%u\bu \"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bs_\be_\br_\bi_\ba_\bl _\bn_\bu_\bm_\bb_\be_\br>\n", + "\n", + " If the −\b−l\bl option is specified, the following information shall be writ‐\n", + " ten for files other than character special and block special files:\n", + "\n", + " \"\b\"%\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bm_\bo_\bd_\be>, <_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bl_\bi_\bn_\bk_\bs>,\n", + " <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be>, <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be>, <_\bs_\bi_\bz_\be>, <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be>,\n", + " <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be>\n", + "\n", + " If the −\b−l\bl option is specified, the following information shall be writ‐\n", + " ten for character special and block special files:\n", + "\n", + " \"\b\"%\b%s\bs %\b%u\bu %\b%s\bs %\b%s\bs %\b%s\bs %\b%s\bs %\b%s\bs\\\b\\n\bn\"\b\",\b, <\b<_\bf_\bi_\bl_\be _\bm_\bo_\bd_\be>, <_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bl_\bi_\bn_\bk_\bs>,\n", + " <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be>, <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be>, <_\bd_\be_\bv_\bi_\bc_\be _\bi_\bn_\bf_\bo>, <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be>,\n", + " <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be>\n", + "\n", + " In both cases if the file is a symbolic link and the −\b−L\bL option is also\n", + " specified, this information shall be for the file resolved from the\n", + " symbolic link, except that the <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be> field shall contain the path‐\n", + " name of the symbolic link itself. If the file is a symbolic link and\n", + " the −\b−L\bL option is not specified, this information shall be about the\n", + " link itself and the <_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be> field shall be of the form:\n", + "\n", + " \"\b\"%\b%s\bs −\b−>\b> %\b%s\bs\"\b\",\b, <\b<_\bp_\ba_\bt_\bh_\bn_\ba_\bm_\be _\bo_\bf _\bl_\bi_\bn_\bk>, <_\bc_\bo_\bn_\bt_\be_\bn_\bt_\bs _\bo_\bf _\bl_\bi_\bn_\bk>\n", + "\n", + " The −\b−n\bn, −\b−g\bg, and −\b−o\bo options use the same format as −\b−l\bl, but with omitted\n", + " items and their associated characters. See the OPTIONS section.\n", + "\n", + " In both the preceding −\b−l\bl forms, if <_\bo_\bw_\bn_\be_\br _\bn_\ba_\bm_\be> or <_\bg_\br_\bo_\bu_\bp _\bn_\ba_\bm_\be> cannot\n", + " be determined, or if −\b−n\bn is given, they shall be replaced with their\n", + " associated numeric values using the format %\b%u\bu.\n", + "\n", + " The <_\bs_\bi_\bz_\be> field shall contain the value that would be returned for the\n", + " file in the _\bs_\bt_\b__\bs_\bi_\bz_\be field of s\bst\btr\bru\buc\bct\bt s\bst\bta\bat\bt (see the Base Definitions vol‐\n", + " ume of POSIX.1‐2008, <\b\b>). Note that for some file types this\n", + " value is unspecified.\n", + "\n", + " The <_\bd_\be_\bv_\bi_\bc_\be _\bi_\bn_\bf_\bo> field shall contain implementation-defined informa‐\n", + " tion associated with the device in question.\n", + "\n", + " The <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be> field shall contain the appropriate date and time‐\n", + " stamp of when the file was last modified. In the POSIX locale, the\n", + " field shall be the equivalent of the output of the following _\bd_\ba_\bt_\be com‐\n", + " mand:\n", + "\n", + " d\bda\bat\bte\be \"\b\"+\b+%\b%b\bb %\b%e\be %\b%H\bH:\b:%\b%M\bM\"\b\"\n", + "\n", + " if the file has been modified in the last six months, or:\n", + "\n", + " d\bda\bat\bte\be \"\b\"+\b+%\b%b\bb %\b%e\be %\b%Y\bY\"\b\"\n", + "\n", + " (where two characters are used between %\b%e\be and %\b%Y\bY) if the file\n", + " has not been modified in the last six months or if the modification\n", + " date is in the future, except that, in both cases, the final \n", + " produced by _\bd_\ba_\bt_\be shall not be included and the output shall be as if\n", + " the _\bd_\ba_\bt_\be command were executed at the time of the last modification\n", + " date of the file rather than the current time. When the _\bL_\bC_\b__\bT_\bI_\bM_\bE locale\n", + " category is not set to the POSIX locale, a different format and order\n", + " of presentation of this field may be used.\n", + "\n", + " If the pathname was specified as a _\bf_\bi_\bl_\be operand, it shall be written as\n", + " specified.\n", + "\n", + " The file mode written under the −\b−l\bl, −\b−n\bn, −\b−g\bg, and −\b−o\bo options shall con‐\n", + " sist of the following format:\n", + "\n", + " \"\b\"%\b%c\bc%\b%s\bs%\b%s\bs%\b%s\bs%\b%s\bs\"\b\",\b, <\b<_\be_\bn_\bt_\br_\by _\bt_\by_\bp_\be>, <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>,\n", + " <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>,\n", + " <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg>\n", + "\n", + " The <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg> shall be the empty string\n", + " if there is no alternate or additional access control method associated\n", + " with the file; otherwise, it shall be a string containing a single\n", + " printable character that is not a .\n", + "\n", + " The <_\be_\bn_\bt_\br_\by _\bt_\by_\bp_\be> character shall describe the type of file, as follows:\n", + "\n", + " d Directory.\n", + "\n", + " b Block special file.\n", + "\n", + " c Character special file.\n", + "\n", + " l (ell) Symbolic link.\n", + "\n", + " p FIFO.\n", + "\n", + " − Regular file.\n", + "\n", + " Implementations may add other characters to this list to represent\n", + " other implementation-defined file types.\n", + "\n", + " The next three fields shall be three characters each:\n", + "\n", + " <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file owner class (see the Base Definitions\n", + " volume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b4_\b._\b4, _\bF_\bi_\bl_\be _\bA_\bc_\bc_\be_\bs_\bs _\bP_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs).\n", + "\n", + " <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file group class.\n", + "\n", + " <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>\n", + " Permissions for the file other class.\n", + "\n", + " Each field shall have three character positions:\n", + "\n", + " 1. If '\b'r\br'\b', the file is readable; if '\b'−\b−'\b', the file is not readable.\n", + "\n", + " 2. If '\b'w\bw'\b', the file is writable; if '\b'−\b−'\b', the file is not writable.\n", + "\n", + " 3. The first of the following that applies:\n", + "\n", + " S If in <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is not executable and\n", + " set-user-ID mode is set. If in <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file\n", + " is not executable and set-group-ID mode is set.\n", + "\n", + " s If in <_\bo_\bw_\bn_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is executable and set-\n", + " user-ID mode is set. If in <_\bg_\br_\bo_\bu_\bp _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs>, the file is\n", + " executable and set-group-ID mode is set.\n", + "\n", + " T If in <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs> and the file is a directory, search\n", + " permission is not granted to others, and the restricted dele‐\n", + " tion flag is set.\n", + "\n", + " t If in <_\bo_\bt_\bh_\be_\br _\bp_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs> and the file is a directory, search\n", + " permission is granted to others, and the restricted deletion\n", + " flag is set.\n", + "\n", + " x The file is executable or the directory is searchable.\n", + "\n", + " − None of the attributes of '\b'S\bS'\b', '\b's\bs'\b', '\b'T\bT'\b', '\b't\bt'\b', or '\b'x\bx'\b' applies.\n", + "\n", + " Implementations may add other characters to this list for the third\n", + " character position. Such additions shall, however, be written in\n", + " lowercase if the file is executable or searchable, and in uppercase\n", + " if it is not.\n", + "\n", + " If any of the −\b−l\bl, −\b−n\bn, −\b−s\bs, −\b−g\bg, or −\b−o\bo options is specified, each list of\n", + " files within the directory shall be preceded by a status line indicat‐\n", + " ing the number of file system blocks occupied by files in the directory\n", + " in 512-byte units if the −\b−k\bk option is not specified, or 1024-byte units\n", + " if the −\b−k\bk option is specified, rounded up to the next integral number\n", + " of units, if necessary. In the POSIX locale, the format shall be:\n", + "\n", + " \"\b\"t\bto\bot\bta\bal\bl %\b%u\bu\\\b\\n\bn\"\b\",\b, <\b<_\bn_\bu_\bm_\bb_\be_\br _\bo_\bf _\bu_\bn_\bi_\bt_\bs _\bi_\bn _\bt_\bh_\be _\bd_\bi_\br_\be_\bc_\bt_\bo_\br_\by>\n", + "\n", + " If more than one directory, or a combination of non-directory files and\n", + " directories are written, either as a result of specifying multiple op‐\n", + " erands, or the −\b−R\bR option, each list of files within a directory shall\n", + " be preceded by:\n", + "\n", + " \"\b\"\\\b\\n\bn%\b%s\bs:\b:\\\b\\n\bn\"\b\",\b, <\b<_\bd_\bi_\br_\be_\bc_\bt_\bo_\br_\by _\bn_\ba_\bm_\be>\n", + "\n", + " If this string is the first thing to be written, the first \n", + " shall not be written. This output shall precede the number of units in\n", + " the directory.\n", + "\n", + " If the −\b−s\bs option is given, each file shall be written with the number\n", + " of blocks used by the file. Along with −\b−C\bC, −\b−1\b1, −\b−m\bm, or −\b−x\bx, the number\n", + " and a shall precede the filename; with −\b−l\bl, −\b−n\bn, −\b−g\bg, or −\b−o\bo, they\n", + " shall precede each line describing a file.\n", + "\n", + "S\bST\bTD\bDE\bER\bRR\bR\n", + " The standard error shall be used only for diagnostic messages.\n", + "\n", + "O\bOU\bUT\bTP\bPU\bUT\bT F\bFI\bIL\bLE\bES\bS\n", + " None.\n", + "\n", + "E\bEX\bXT\bTE\bEN\bND\bDE\bED\bD D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN\n", + " None.\n", + "\n", + "E\bEX\bXI\bIT\bT S\bST\bTA\bAT\bTU\bUS\bS\n", + " The following exit values shall be returned:\n", + "\n", + " 0 Successful completion.\n", + "\n", + " >0 An error occurred.\n", + "\n", + "C\bCO\bON\bNS\bSE\bEQ\bQU\bUE\bEN\bNC\bCE\bES\bS O\bOF\bF E\bER\bRR\bRO\bOR\bRS\bS\n", + " Default.\n", + "\n", + " _\bT_\bh_\be _\bf_\bo_\bl_\bl_\bo_\bw_\bi_\bn_\bg _\bs_\be_\bc_\bt_\bi_\bo_\bn_\bs _\ba_\br_\be _\bi_\bn_\bf_\bo_\br_\bm_\ba_\bt_\bi_\bv_\be_\b.\n", + "\n", + "A\bAP\bPP\bPL\bLI\bIC\bCA\bAT\bTI\bIO\bON\bN U\bUS\bSA\bAG\bGE\bE\n", + " Many implementations use the ('\b'=\b='\b') to denote sockets\n", + " bound to the file system for the −\b−F\bF option. Similarly, many historical\n", + " implementations use the '\b's\bs'\b' character to denote sockets as the entry\n", + " type characters for the −\b−l\bl option.\n", + "\n", + " It is difficult for an application to use every part of the file modes\n", + " field of _\bl_\bs −\b−l\bl in a portable manner. Certain file types and executable\n", + " bits are not guaranteed to be exactly as shown, as implementations may\n", + " have extensions. Applications can use this field to pass directly to a\n", + " user printout or prompt, but actions based on its contents should gen‐\n", + " erally be deferred, instead, to the _\bt_\be_\bs_\bt utility.\n", + "\n", + " The output of _\bl_\bs (with the −\b−l\bl and related options) contains information\n", + " that logically could be used by utilities such as _\bc_\bh_\bm_\bo_\bd and _\bt_\bo_\bu_\bc_\bh to\n", + " restore files to a known state. However, this information is presented\n", + " in a format that cannot be used directly by those utilities or be eas‐\n", + " ily translated into a format that can be used. A character has been\n", + " added to the end of the permissions string so that applications at\n", + " least have an indication that they may be working in an area they do\n", + " not understand instead of assuming that they can translate the permis‐\n", + " sions string into something that can be used. Future versions or\n", + " related documents may define one or more specific characters to be used\n", + " based on different standard additional or alternative access control\n", + " mechanisms.\n", + "\n", + " As with many of the utilities that deal with filenames, the output of\n", + " _\bl_\bs for multiple files or in one of the long listing formats must be\n", + " used carefully on systems where filenames can contain embedded white\n", + " space. Systems and system administrators should institute policies and\n", + " user training to limit the use of such filenames.\n", + "\n", + " The number of disk blocks occupied by the file that it reports varies\n", + " depending on underlying file system type, block size units reported,\n", + " and the method of calculating the number of blocks. On some file system\n", + " types, the number is the actual number of blocks occupied by the file\n", + " (counting indirect blocks and ignoring holes in the file); on others it\n", + " is calculated based on the file size (usually making an allowance for\n", + " indirect blocks, but ignoring holes).\n", + "\n", + "E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS\n", + " An example of a small directory tree being fully listed with _\bl_\bs −\b−l\bla\baR\bRF\bF a\ba\n", + " in the POSIX locale:\n", + "\n", + " t\bto\bot\bta\bal\bl 1\b11\b1\n", + " d\bdr\brw\bwx\bxr\br-\b-x\bxr\br-\b-x\bx 3\b3 f\bfo\box\bx p\bpr\bro\bog\bg 6\b64\b4 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 .\b./\b/\n", + " d\bdr\brw\bwx\bxr\brw\bwx\bxr\brw\bwx\bx 4\b4 f\bfo\box\bx p\bpr\bro\bog\bg 3\b32\b26\b64\b4 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b09\b9 .\b..\b./\b/\n", + " d\bdr\brw\bwx\bxr\br-\b-x\bxr\br-\b-x\bx 2\b2 f\bfo\box\bx p\bpr\bro\bog\bg 4\b48\b8 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 b\bb/\b/\n", + " -\b-r\brw\bwx\bxr\br-\b--\b-r\br-\b--\b- 1\b1 f\bfo\box\bx p\bpr\bro\bog\bg 5\b57\b72\b2 J\bJu\bul\bl 4\b4 1\b12\b2:\b:0\b07\b7 f\bfo\boo\bo*\b*\n", + "\n", + " a/b:\n", + " total 4\n", + " drwxr-xr-x 2 fox prog 48 Jul 4 12:07 ./\n", + " drwxr-xr-x 3 fox prog 64 Jul 4 12:07 ../\n", + " -rw-r--r-- 1 fox prog 700 Jul 4 12:07 bar\n", + "\n", + "R\bRA\bAT\bTI\bIO\bON\bNA\bAL\bLE\bE\n", + " Some historical implementations of the _\bl_\bs utility show all entries in a\n", + " directory except dot and dot-dot when a superuser invokes _\bl_\bs without\n", + " specifying the −\b−a\ba option. When ``normal'' users invoke _\bl_\bs without spec‐\n", + " ifying −\b−a\ba, they should not see information about any files with names\n", + " beginning with a unless they were named as _\bf_\bi_\bl_\be operands.\n", + "\n", + " Implementations are expected to traverse arbitrary depths when process‐\n", + " ing the −\b−R\bR option. The only limitation on depth should be based on run‐\n", + " ning out of physical storage for keeping track of untraversed directo‐\n", + " ries.\n", + "\n", + " The −\b−1\b1 (one) option was historically found in BSD and BSD-derived\n", + " implementations only. It is required in this volume of POSIX.1‐2008 so\n", + " that conforming applications might ensure that output is one entry per\n", + " line, even if the output is to a terminal.\n", + "\n", + " The −\b−S\bS option was added in Issue 7, but had been provided by several\n", + " implementations for many years. The description given in the standard\n", + " documents historic practice, but does not match much of the documenta‐\n", + " tion that described its behavior. Historical documentation typically\n", + " described it as something like:\n", + "\n", + " −\b−S\bS Sort by size (largest size first) instead of by name. Special\n", + " character devices (listed last) are sorted by name.\n", + "\n", + " even though the file type was never considered when sorting the output.\n", + " Character special files do typically sort close to the end of the list\n", + " because their file size on most implementations is zero. But they are\n", + " sorted alphabetically with any other files that happen to have the same\n", + " file size (zero), not sorted separately and added to the end.\n", + "\n", + " This volume of POSIX.1‐2008 is frequently silent about what happens\n", + " when mutually-exclusive options are specified. Except for −\b−R\bR, −\b−d\bd, and\n", + " −\b−f\bf, the _\bl_\bs utility is required to accept multiple options from each\n", + " mutually-exclusive option set without treating them as errors and to\n", + " use the behavior specified by the last option given in each mutually-\n", + " exclusive set. Since _\bl_\bs is one of the most aliased commands, it is\n", + " important that the implementation perform intuitively. For example, if\n", + " the alias were:\n", + "\n", + " a\bal\bli\bia\bas\bs l\bls\bs=\b=\"\b\"l\bls\bs −\b−C\bC\"\b\"\n", + "\n", + " and the user typed _\bl_\bs −\b−1\b1 (one), single-text-column output should\n", + " result, not an error.\n", + "\n", + " The −\b−g\bg, −\b−l\bl (ell), −\b−n\bn, and −\b−o\bo options are not mutually-exclusive\n", + " options. They all enable long format output. They work together to\n", + " determine whether the file's owner is written (no if −\b−g\bg is present),\n", + " file's group is written (no if −\b−o\bo is present), and if the file's group\n", + " or owner is written whether it is written as the name (default) or a\n", + " string representation of the UID or GID number (if −\b−n\bn is present). The\n", + " −\b−C\bC, −\b−m\bm, −\b−x\bx, and −\b−1\b1 (one) are mutually-exclusive options and the first\n", + " three of these disable long format output. The −\b−1\b1 (one) option does not\n", + " directly change whether or not long format output is enabled, but by\n", + " overriding −\b−C\bC, −\b−m\bm, and −\b−x\bx, it can re-enable long format output that had\n", + " been disabled by one of these options.\n", + "\n", + " Earlier versions of this standard did not describe the BSD −\b−A\bA option\n", + " (like −\b−a\ba, but dot and dot-dot are not written out). It has been added\n", + " due to widespread implementation.\n", + "\n", + " Implementations may make −\b−q\bq the default for terminals to prevent trojan\n", + " horse attacks on terminals with special escape sequences. This is not\n", + " required because:\n", + "\n", + " * Some control characters may be useful on some terminals; for exam‐\n", + " ple, a system might write them as \"\b\"\\\b\\0\b00\b01\b1\"\b\" or \"\b\"^\b^A\bA\"\b\".\n", + "\n", + " * Special behavior for terminals is not relevant to applications\n", + " portability.\n", + "\n", + " An early proposal specified that the <_\bo_\bp_\bt_\bi_\bo_\bn_\ba_\bl _\ba_\bl_\bt_\be_\br_\b‐\n", + " _\bn_\ba_\bt_\be _\ba_\bc_\bc_\be_\bs_\bs _\bm_\be_\bt_\bh_\bo_\bd _\bf_\bl_\ba_\bg> had to be '\b'+\b+'\b' if there was an alternate access\n", + " method used on the file or if there was not. This was changed\n", + " to be if there is not and a single printable character if there\n", + " is. This was done for three reasons:\n", + "\n", + " 1. There are historical implementations using characters other than\n", + " '\b'+\b+'\b'.\n", + "\n", + " 2. There are implementations that vary this character used in that\n", + " position to distinguish between various alternate access methods in\n", + " use.\n", + "\n", + " 3. The standard developers did not want to preclude future specifica‐\n", + " tions that might need a way to specify more than one alternate\n", + " access method.\n", + "\n", + " Nonetheless, implementations providing a single alternate access method\n", + " are encouraged to use '\b'+\b+'\b'.\n", + "\n", + " Earlier versions of this standard did not have the −\b−k\bk option, which\n", + " meant that the −\b−s\bs option could not be used portably as its block size\n", + " was implementation-defined, and the units used to specify the number of\n", + " blocks occupied by files in a directory in an _\bl_\bs −\b−l\bl listing were fixed\n", + " as 512-byte units. The −\b−k\bk option has been added to provide a way for\n", + " the −\b−s\bs option to be used portably, and for consistency it also changes\n", + " the aforementioned units from 512-byte to 1024-byte.\n", + "\n", + " The <_\bd_\ba_\bt_\be _\ba_\bn_\bd _\bt_\bi_\bm_\be> field in the −\b−l\bl format is specified only for the\n", + " POSIX locale. As noted, the format can be different in other locales.\n", + " No mechanism for defining this is present in this volume of\n", + " POSIX.1‐2008, as the appropriate vehicle is a messaging system; that\n", + " is, the format should be specified as a ``message''.\n", + "\n", + "F\bFU\bUT\bTU\bUR\bRE\bE D\bDI\bIR\bRE\bEC\bCT\bTI\bIO\bON\bNS\bS\n", + " Allowing −\b−f\bf to ignore the −\b−A\bA, −\b−g\bg, −\b−l\bl, −\b−n\bn, −\b−o\bo, and −\b−s\bs options may be\n", + " removed in a future version.\n", + "\n", + "S\bSE\bEE\bE A\bAL\bLS\bSO\bO\n", + " _\bc_\bh_\bm_\bo_\bd, _\bf_\bi_\bn_\bd\n", + "\n", + " The Base Definitions volume of POSIX.1‐2008, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b4_\b._\b4, _\bF_\bi_\bl_\be _\bA_\bc_\bc_\be_\bs_\bs\n", + " _\bP_\be_\br_\bm_\bi_\bs_\bs_\bi_\bo_\bn_\bs, _\bC_\bh_\ba_\bp_\bt_\be_\br _\b8, _\bE_\bn_\bv_\bi_\br_\bo_\bn_\bm_\be_\bn_\bt _\bV_\ba_\br_\bi_\ba_\bb_\bl_\be_\bs, _\bS_\be_\bc_\bt_\bi_\bo_\bn _\b1_\b2_\b._\b2, _\bU_\bt_\bi_\bl_\bi_\bt_\by\n", + " _\bS_\by_\bn_\bt_\ba_\bx _\bG_\bu_\bi_\bd_\be_\bl_\bi_\bn_\be_\bs, <\b\b>\n", + "\n", + " The System Interfaces volume of POSIX.1‐2008, _\bf_\bs_\bt_\ba_\bt_\ba_\bt()\n", + "\n", + "C\bCO\bOP\bPY\bYR\bRI\bIG\bGH\bHT\bT\n", + " Portions of this text are reprinted and reproduced in electronic form\n", + " from IEEE Std 1003.1, 2013 Edition, Standard for Information Technology\n", + " -- Portable Operating System Interface (POSIX), The Open Group Base\n", + " Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐\n", + " cal and Electronics Engineers, Inc and The Open Group. (This is\n", + " POSIX.1-2008 with the 2013 Technical Corrigendum 1 applied.) In the\n", + " event of any discrepancy between this version and the original IEEE and\n", + " The Open Group Standard, the original IEEE and The Open Group Standard\n", + " is the referee document. The original Standard can be obtained online\n", + " at http://www.unix.org/online.html .\n", + "\n", + " Any typographical or formatting errors that appear in this page are\n", + " most likely to have been introduced during the conversion of the source\n", + " files to man page format. To report such errors, see https://www.ker‐\n", + " nel.org/doc/man-pages/reporting_bugs.html .\n", + "\n", + "IEEE/The Open Group 2013 LS(1POSIX)\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# q\n", + "bash: q: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo Hello World\n", + "Hello World\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# path\n", + "bash: path: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# PATH\n", + "bash: PATH: command not found\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo $PATH\n", + "/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/tools/node/bin:/tools/google-cloud-sdk/bin:/opt/bin\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# echo $SHELL\n", + "/bin/bash\n", + "\u001b]0;root@a6cc2b6772dd: /content\u0007\u001b[01;32mroot@a6cc2b6772dd\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "YoEgruUhqvzw", + "colab_type": "text" + }, + "source": [ + "## Navigating Directories\n", + "\n", + "You can change your current directory using the \"cd\" shell command. Note that \"cd\" is not a Unix program. Once in a directory, you can use the \"ls\" command to list the contents or \"pwd\" to remind yourself your current working directory. You can move back one level in your current directory hierarchy using \"cd ..\". In general \"..\" represents the path to a directory one level above your current directory, \"../..\" represents two levels up, and so on. \".\" represents the current directory. If you look at the PATH environment variable, you'll notice that the last item is \".\", telling the shell to look into your current directory for commands. Finally the \"~\" character always refers to your home directory.\n", + "\n", + "Some other file manipulation commands:\n", + "\n", + " - The \"mkdir\" command creates new directories. \n", + " - \"cp\" and \"mv\" allow you to copy and move (or rename) files, taking 2 arguments: the original path/filename and the target path/filename. \n", + " - The \"rm\" and \"rmdir\" commands remove (delete) files and directories.\n", + "\n", + "\n", + "*Exercise 2:* Using the \"cd\" command, navigate into \"drive/My\\ Drive\" directory. Create a new directory called \"Data-1441\", and another directory inside \"Data-1441\" called \"Lab-1-Solutions\". Perform the rest of the lab in this directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "A16VzZ3G0J8x", + "colab_type": "code", + "outputId": "c931496a-f7ba-4df7-f530-d79f6ec9f679", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 272 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# pwd\n", + "/content\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# drive/My\\Drive\n", + "bash: drive/MyDrive: No such file or directory\n", + "\u001b]0;root@47551fbb9a44: /content/drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive\u001b[00m# cd My\\ Drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# pwd\n", + "/content/drive/My Drive\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# mkdir Data-1401\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive\u001b[00m# cd Data-1401\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive/Data-1401\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1401\u001b[00m# mkdir Lab-1-Solutions\n", + "\u001b]0;root@47551fbb9a44: /content/drive/My Drive/Data-1401\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content/drive/My Drive/Data-1401\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o38c4lbsqvzy", + "colab_type": "text" + }, + "source": [ + "## Exploring Unix Filesystem\n", + "\n", + "You can look at the root directory of the system by issuing \"ls /\". As explained in lecture, Unix uses the file system to communicate with devices and between processes. \"/etc\" keeps the configuration files of the system. \"/bin\" and \"/sbin\" store most of the standard Unix programs. \"/usr\" stores installes programs and their associate files, with \"/usr/bin\" usually storing the commands you can run. \n", + "\n", + "*Exercise 3:* List the \"/dev\" directory. How many SSD storage devices do you see? How many partitions does each device have? (Answer in box below)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "yNj2LXzP2ksl", + "colab_type": "code", + "outputId": "c96151ba-85c9-4f7b-e793-3aae6d124a94", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# ls /dev\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@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cd /dev\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# pwd\n", + "/dev\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# df --help\n", + "Usage: df [OPTION]... [FILE]...\n", + "Show information about the file system on which each FILE resides,\n", + "or all file systems by default.\n", + "\n", + "Mandatory arguments to long options are mandatory for short options too.\n", + " -a, --all include pseudo, duplicate, inaccessible file systems\n", + " -B, --block-size=SIZE scale sizes by SIZE before printing them; e.g.,\n", + " '-BM' prints sizes in units of 1,048,576 bytes;\n", + " see SIZE format below\n", + " -h, --human-readable print sizes in powers of 1024 (e.g., 1023M)\n", + " -H, --si print sizes in powers of 1000 (e.g., 1.1G)\n", + " -i, --inodes list inode information instead of block usage\n", + " -k like --block-size=1K\n", + " -l, --local limit listing to local file systems\n", + " --no-sync do not invoke sync before getting usage info (default)\n", + " --output[=FIELD_LIST] use the output format defined by FIELD_LIST,\n", + " or print all fields if FIELD_LIST is omitted.\n", + " -P, --portability use the POSIX output format\n", + " --sync invoke sync before getting usage info\n", + " --total elide all entries insignificant to available space,\n", + " and produce a grand total\n", + " -t, --type=TYPE limit listing to file systems of type TYPE\n", + " -T, --print-type print file system type\n", + " -x, --exclude-type=TYPE limit listing to file systems not of type TYPE\n", + " -v (ignored)\n", + " --help display this help and exit\n", + " --version output version information and exit\n", + "\n", + "Display values are in units of the first available SIZE from --block-size,\n", + "and the DF_BLOCK_SIZE, BLOCK_SIZE and BLOCKSIZE environment variables.\n", + "Otherwise, units default to 1024 bytes (or 512 if POSIXLY_CORRECT is set).\n", + "\n", + "The SIZE argument is an integer and optional unit (example: 10K is 10*1024).\n", + "Units are K,M,G,T,P,E,Z,Y (powers of 1024) or KB,MB,... (powers of 1000).\n", + "\n", + "FIELD_LIST is a comma-separated list of columns to be included. Valid\n", + "field names are: 'source', 'fstype', 'itotal', 'iused', 'iavail', 'ipcent',\n", + "'size', 'used', 'avail', 'pcent', 'file' and 'target' (see info page).\n", + "\n", + "GNU coreutils online help: \n", + "Full documentation at: \n", + "or available locally via: info '(coreutils) df invocation'\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# df -H\n", + "Filesystem Size Used Avail Use% Mounted on\n", + "overlay 116G 31G 80G 28% /\n", + "tmpfs 68M 0 68M 0% /dev\n", + "tmpfs 6.9G 0 6.9G 0% /sys/fs/cgroup\n", + "tmpfs 6.9G 8.2k 6.9G 1% /var/colab\n", + "/dev/sda1 123G 33G 91G 27% /etc/hosts\n", + "shm 6.5G 4.1k 6.5G 1% /dev/shm\n", + "tmpfs 6.9G 0 6.9G 0% /proc/acpi\n", + "tmpfs 6.9G 0 6.9G 0% /proc/scsi\n", + "tmpfs 6.9G 0 6.9G 0% /sys/firmware\n", + "drive 17G 585M 16G 4% /content/drive\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# lsblk --help\n", + "\n", + "Usage:\n", + " lsblk [options] [ ...]\n", + "\n", + "List information about block devices.\n", + "\n", + "Options:\n", + " -a, --all print all devices\n", + " -b, --bytes print SIZE in bytes rather than in human readable format\n", + " -d, --nodeps don't print slaves or holders\n", + " -D, --discard print discard capabilities\n", + " -z, --zoned print zone model\n", + " -e, --exclude exclude devices by major number (default: RAM disks)\n", + " -f, --fs output info about filesystems\n", + " -i, --ascii use ascii characters only\n", + " -I, --include show only devices with specified major numbers\n", + " -J, --json use JSON output format\n", + " -l, --list use list format output\n", + " -T, --tree use tree format output\n", + " -m, --perms output info about permissions\n", + " -n, --noheadings don't print headings\n", + " -o, --output output columns\n", + " -O, --output-all output all columns\n", + " -p, --paths print complete device path\n", + " -P, --pairs use key=\"value\" output format\n", + " -r, --raw use raw output format\n", + " -s, --inverse inverse dependencies\n", + " -S, --scsi output info about SCSI devices\n", + " -t, --topology output info about topology\n", + " -x, --sort sort output by \n", + "\n", + " -h, --help display this help\n", + " -V, --version display version\n", + "\n", + "Available output columns:\n", + " NAME device name\n", + " KNAME internal kernel device name\n", + " MAJ:MIN major:minor device number\n", + " FSTYPE filesystem type\n", + " MOUNTPOINT where the device is mounted\n", + " LABEL filesystem LABEL\n", + " UUID filesystem UUID\n", + " PARTTYPE partition type UUID\n", + " PARTLABEL partition LABEL\n", + " PARTUUID partition UUID\n", + " PARTFLAGS partition flags\n", + " RA read-ahead of the device\n", + " RO read-only device\n", + " RM removable device\n", + " HOTPLUG removable or hotplug device (usb, pcmcia, ...)\n", + " MODEL device identifier\n", + " SERIAL disk serial number\n", + " SIZE size of the device\n", + " STATE state of the device\n", + " OWNER user name\n", + " GROUP group name\n", + " MODE device node permissions\n", + " ALIGNMENT alignment offset\n", + " MIN-IO minimum I/O size\n", + " OPT-IO optimal I/O size\n", + " PHY-SEC physical sector size\n", + " LOG-SEC logical sector size\n", + " ROTA rotational device\n", + " SCHED I/O scheduler name\n", + " RQ-SIZE request queue size\n", + " TYPE device type\n", + " DISC-ALN discard alignment offset\n", + " DISC-GRAN discard granularity\n", + " DISC-MAX discard max bytes\n", + " DISC-ZERO discard zeroes data\n", + " WSAME write same max bytes\n", + " WWN unique storage identifier\n", + " RAND adds randomness\n", + " PKNAME internal parent kernel device name\n", + " HCTL Host:Channel:Target:Lun for SCSI\n", + " TRAN device transport type\n", + " SUBSYSTEMS de-duplicated chain of subsystems\n", + " REV device revision\n", + " VENDOR device vendor\n", + " ZONED zone model\n", + "\n", + "For more details see lsblk(8).\n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# lsblk\n", + "NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT\n", + "loop0 7:0 0 110G 0 loop \n", + "sda 8:0 0 120G 0 disk \n", + "├─sda1 8:1 115.9G 0 part /etc/hosts\n", + "├─sda2 8:2 0 16M 0 part \n", + "├─sda3 8:3 0 2G 0 part \n", + "├─sda4 8:4 0 16M 0 part \n", + "├─sda5 8:5 0 2G 0 part \n", + "├─sda6 8:6 512B 0 part \n", + "├─sda7 8:7 0 512B 0 part \n", + "├─sda8 8:8 16M 0 part \n", + "├─sda9 8:9 0 512B 0 part \n", + "├─sda10 8:10 0 512B 0 part \n", + "├─sda11 8:11 8M 0 part \n", + "└─sda12 8:12 0 32M 0 part \n", + "\u001b]0;root@47551fbb9a44: /dev\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/dev\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "7P9EG0KOqvz2", + "colab_type": "text" + }, + "source": [ + "## Text File Manipulation\n", + "\n", + "As explained in lecture, Unix stores most information in text files. For example, the list of all users and their home directories are stored in \"/etc/passwd\". Let get some familiarity with the most commonly used commands to manipulate files.\n", + "\n", + " - You can see the contents contents a file using the \"cat\" (concatenate) command. Try executing \"cat /etc/passwd\". You'll get a huge list that will go by your screen quickly. \n", + " \n", + " - To go through the file page by page, you can use the \"less\" or \"more\" commands. \n", + " \n", + " - You can see the first or last N (N=10 by default) lines of a file using \"head\" or \"tail\" commands. For example \"tail -20 /etc/passwd\" will list the last 20 lines. \n", + " \n", + " - You can search a test file using the \"grep\" command, which takes a string keyword as the first argument and a filename as the second, and by default prints out every line in the file that contrains the string. So for example you can do \"grep \\$USER /etc/passwd\" to find the line corresponding to your account. Some useful flags: \n", + " \n", + " - \"-i\" ignores the case of the keyword\n", + " - \"-v\" display those lines that do NOT match \n", + " - \"-n\" precede each matching line with the line number \n", + " - \"-c\" print only the total count of matched lines \n", + " \n", + " For example \"grep -c \\$USER /etc/passwd\" should show that you are in the password file just once. \n", + " \n", + " - The \"wc\" (word count) command counts the number of lines, words, and characters in a file. By default \"wc\" gives you all three numbers, but \"-w\", \"-l\", or \"-c\" flags \n", + "\n", + "*Exercise 4:* Count how many lines in the password file contain the letter \"w\". " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "UlsANMuf2qMs", + "colab_type": "code", + "outputId": "848dba2c-0729-4973-8c17-242783190c40", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# head -n\n", + "head: option requires an argument -- 'n'\n", + "Try 'head --help' for more information.\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# head -n 5 /etc/passwd\n", + "root:x:0:0:root:/root:/bin/bash\n", + "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n", + "bin:x:2:2:bin:/bin:/usr/sbin/nologin\n", + "sys:x:3:3:sys:/dev:/usr/sbin/nologin\n", + "sync:x:4:65534:sync:/bin:/bin/sync\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat /etc/passwd\n", + "root:x:0:0:root:/root:/bin/bash\n", + "daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n", + "bin:x:2:2:bin:/bin:/usr/sbin/nologin\n", + "sys:x:3:3:sys:/dev:/usr/sbin/nologin\n", + "sync:x:4:65534:sync:/bin:/bin/sync\n", + "games:x:5:60:games:/usr/games:/usr/sbin/nologin\n", + "man:x:6:12:man:/var/cache/man:/usr/sbin/nologin\n", + "lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin\n", + "mail:x:8:8:mail:/var/mail:/usr/sbin/nologin\n", + "news:x:9:9:news:/var/spool/news:/usr/sbin/nologin\n", + "uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin\n", + "proxy:x:13:13:proxy:/bin:/usr/sbin/nologin\n", + "www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin\n", + "backup:x:34:34:backup:/var/backups:/usr/sbin/nologin\n", + "list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin\n", + "irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin\n", + "gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin\n", + "nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin\n", + "_apt:x:100:65534::/nonexistent:/usr/sbin/nologin\n", + "systemd-network:x:101:104:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin\n", + "systemd-resolve:x:102:105:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin\n", + "messagebus:x:103:107::/nonexistent:/usr/sbin/nologin\n", + "nvidia-persistenced:x:104:108:NVIDIA Persistence Daemon,,,:/nonexistent:/sbin/nologin\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep --help\n", + "Usage: grep [OPTION]... PATTERN [FILE]...\n", + "Search for PATTERN in each FILE.\n", + "Example: grep -i 'hello world' menu.h main.c\n", + "\n", + "Pattern selection and interpretation:\n", + " -E, --extended-regexp PATTERN is an extended regular expression\n", + " -F, --fixed-strings PATTERN is a set of newline-separated strings\n", + " -G, --basic-regexp PATTERN is a basic regular expression (default)\n", + " -P, --perl-regexp PATTERN is a Perl regular expression\n", + " -e, --regexp=PATTERN use PATTERN for matching\n", + " -f, --file=FILE obtain PATTERN from FILE\n", + " -i, --ignore-case ignore case distinctions\n", + " -w, --word-regexp force PATTERN to match only whole words\n", + " -x, --line-regexp force PATTERN to match only whole lines\n", + " -z, --null-data a data line ends in 0 byte, not newline\n", + "\n", + "Miscellaneous:\n", + " -s, --no-messages suppress error messages\n", + " -v, --invert-match select non-matching lines\n", + " -V, --version display version information and exit\n", + " --help display this help text and exit\n", + "\n", + "Output control:\n", + " -m, --max-count=NUM stop after NUM selected lines\n", + " -b, --byte-offset print the byte offset with output lines\n", + " -n, --line-number print line number with output lines\n", + " --line-buffered flush output on every line\n", + " -H, --with-filename print file name with output lines\n", + " -h, --no-filename suppress the file name prefix on output\n", + " --label=LABEL use LABEL as the standard input file name prefix\n", + " -o, --only-matching show only the part of a line matching PATTERN\n", + " -q, --quiet, --silent suppress all normal output\n", + " --binary-files=TYPE assume that binary files are TYPE;\n", + " TYPE is 'binary', 'text', or 'without-match'\n", + " -a, --text equivalent to --binary-files=text\n", + " -I equivalent to --binary-files=without-match\n", + " -d, --directories=ACTION how to handle directories;\n", + " ACTION is 'read', 'recurse', or 'skip'\n", + " -D, --devices=ACTION how to handle devices, FIFOs and sockets;\n", + " ACTION is 'read' or 'skip'\n", + " -r, --recursive like --directories=recurse\n", + " -R, --dereference-recursive likewise, but follow all symlinks\n", + " --include=FILE_PATTERN search only files that match FILE_PATTERN\n", + " --exclude=FILE_PATTERN skip files and directories matching FILE_PATTERN\n", + " --exclude-from=FILE skip files matching any file pattern from FILE\n", + " --exclude-dir=PATTERN directories that match PATTERN will be skipped.\n", + " -L, --files-without-match print only names of FILEs with no selected lines\n", + " -l, --files-with-matches print only names of FILEs with selected lines\n", + " -c, --count print only a count of selected lines per FILE\n", + " -T, --initial-tab make tabs line up (if needed)\n", + " -Z, --null print 0 byte after FILE name\n", + "\n", + "Context control:\n", + " -B, --before-context=NUM print NUM lines of leading context\n", + " -A, --after-context=NUM print NUM lines of trailing context\n", + " -C, --context=NUM print NUM lines of output context\n", + " -NUM same as --context=NUM\n", + " --color[=WHEN],\n", + " --colour[=WHEN] use markers to highlight the matching strings;\n", + " WHEN is 'always', 'never', or 'auto'\n", + " -U, --binary do not strip CR characters at EOL (MSDOS/Windows)\n", + "\n", + "When FILE is '-', read standard input. With no FILE, read '.' if\n", + "recursive, '-' otherwise. With fewer than two FILEs, assume -h.\n", + "Exit status is 0 if any line is selected, 1 otherwise;\n", + "if any error occurs and -q is not given, the exit status is 2.\n", + "\n", + "Report bugs to: bug-grep@gnu.org\n", + "GNU grep home page: \n", + "General help using GNU software: \n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -i 'w' /etc/passwd\n", + "ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:x:9:9:ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:/var/spool/ne\u001b[01;31m\u001b[Kw\u001b[m\u001b[Ks:/usr/sbin/nologin\n", + "\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K-data:x:33:33:\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K-data:/var/\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K\u001b[01;31m\u001b[Kw\u001b[m\u001b[K:/usr/sbin/nologin\n", + "systemd-net\u001b[01;31m\u001b[Kw\u001b[m\u001b[Kork:x:101:104:systemd Net\u001b[01;31m\u001b[Kw\u001b[m\u001b[Kork Management,,,:/run/systemd/netif:/usr/sbin/nologin\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -c 'w' /etc/passwd\n", + "3\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SZuhLbD8qvz5", + "colab_type": "text" + }, + "source": [ + "## Redirection\n", + "\n", + "Unix provides programs \"pipes\" for input and output. Most of what you see on the screen when you run a program was written to the \"stdout\" (standard output) pipe. Other pipes are \"stdin\" (standard input) and \"stderr\" (standard error), where error messages are written.\n", + "\n", + "As discussed in lecture, the basic commands of are simple, but you can chain them to do complicated things. Redirection is how you chain these commands, directing the output of one command to the input of the next.\n", + "\n", + "As an example, consider the \"cat\" command. Cat takes stdin and outputs it to stdout. Type \"cat\" and press enter and confirm. You can get back to the command prompt by pressing \"control-c\" (sends terminate singal) or \"control-d\" (end of file character). Note that from now on we will use the convention: \"control-d\" = \"^D\"\n", + "\n", + "*Exercise 5a:* Using \"cat\" and indirection you can write things into a file. The \">\" symbol directs stdout into a file. Try \"cat > favorite-colors-list.txt\" and then type in your 3 favorite colors, each on it's own line. Use \"^D\" to end your input." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "H5vxtcXnqvz6", + "colab_type": "text" + }, + "source": [ + "Use \"cat\", \"more\", or \"less\" to confirm that you file is as you expect it. \">>\" allows you to append to the file. \n", + "\n", + "*Exercise 5b:* Append 2 more colors to your file." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "twRKNaGy3XGw", + "colab_type": "code", + "outputId": "763bf004-b6e0-4761-b43c-ec3d41d2b707", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat > favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# \n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"white\"\n", + "white\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"white\" >> favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# echo \"pink\" >> favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat favoritecolors\n", + "purple\n", + "blue\n", + "yellow\n", + "white\n", + "pink\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "DZODNKiAqvz8", + "colab_type": "text" + }, + "source": [ + "The \"sort\" command sorts what it sees on stdin. Instead of taking input from the terminal, you can direct the shell to take stdin from a file using \"<\". Try \"sort < favorite-color-list.txt\" and \"sort < favorite-color-list.txt > sorted-favorite-color-list.txt\".\n", + "\n", + "Finally, instead of piping input / output into files, you can directly chain one program into another using \"|\". So for example, you can do \"cat /etc/passwd | grep -i \\$USER | wc -l\". \n", + "\n", + "*Exercise 5c:* Use indirection to count the number of users on TACC with your first name. Copy the command you used into box below." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "oP9XlZl_3iZD", + "colab_type": "code", + "outputId": "c917ad7f-3638-43ae-ad7e-a22664413a68", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 306 + } + }, + "source": [ + "!/bin/bash --noediting" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "bash: cannot set terminal process group (124): Inappropriate ioctl for device\n", + "bash: no job control in this shell\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# sort < favoritecolors\n", + "blue\n", + "pink\n", + "purple\n", + "white\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# sort < favoritecolors > sorted_favoritecolors\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# cat sorted_favoritecolors\n", + "blue\n", + "pink\n", + "purple\n", + "white\n", + "yellow\n", + "\u001b]0;root@47551fbb9a44: /content\u0007\u001b[01;32mroot@47551fbb9a44\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n", + "exit\n" + ], + "name": "stdout" + } + ] + }, + { + "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": "85c2adaa-9c46-43e8-9537-17b96ee170a4", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + } + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive\n", + "'Colab Notebooks' 'Freshmen year' 'HW1 Answers.gdoc'\n", + " Data-1401\t Highschool\t SPAN\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": "3bed7b00-53c6-481e-98b9-a5b49d904788", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fwsBdTnYqv0Q", + "colab_type": "text" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8w42MH6Jqv0S", + "colab_type": "code", + "outputId": "b9d30373-a331-4802-9fa9-485a0d703988", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "# What you past here should look like:\n", + "#!git clone https://github.com//DATA1401-Spring-2020.git\n", + "!git clone https://github.com/bridgetg19/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Cloning into 'DATA1401-Spring-2020'...\n", + "remote: Enumerating objects: 38, done.\u001b[K\n", + "remote: Counting objects: 100% (38/38), done.\u001b[K\n", + "remote: Compressing objects: 100% (25/25), done.\u001b[K\n", + "remote: Total 38 (delta 7), reused 36 (delta 5), pack-reused 0\u001b[K\n", + "Unpacking objects: 100% (38/38), done.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "cOAuqTVUqv0V", + "colab_type": "text" + }, + "source": [ + "Go into the directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "b1Ew4tEZqv0X", + "colab_type": "code", + "outputId": "c601d630-ee66-4990-8be0-260d7024a44e", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "%cd DATA1401-Spring-2020\n", + "!ls" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "/content/drive/My Drive/Data-1401-Repo/DATA1401-Spring-2020\n", + "Labs Lectures\tREADME.md syllabus.pdf\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IrhWToc-qv0a", + "colab_type": "text" + }, + "source": [ + "We will now connect your fork to the original so you can pull changes from there. \n", + "\n", + "Check remote status:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "JxtMYR-9qv0c", + "colab_type": "code", + "outputId": "daa7bd38-d492-40d4-fbbf-5fcf56d5a8bf", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/bridgetg19/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", + "outputId": "1c6a6ea5-655e-4068-dd1c-2f987adc67c1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!git remote add upstream https://github.com/afarbin/DATA1401-Spring-2020.git" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "fatal: remote upstream already exists.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "id2yUEt9qv0k", + "colab_type": "code", + "outputId": "fcf1e13a-d105-463a-925a-2eb9724d8033", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "!git remote -v" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (fetch)\n", + "origin\thttps://github.com/bridgetg19/DATA1401-Spring-2020.git (push)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (fetch)\n", + "upstream\thttps://github.com/afarbin/DATA1401-Spring-2020.git (push)\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "sAkgeJ6Iqv0n", + "colab_type": "text" + }, + "source": [ + "From now on, you can get the newest version of class material by using:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AGDsfTFLqv0o", + "colab_type": "code", + "outputId": "ac4c023e-0a28-4057-ca87-0c0c231463d1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "!git pull" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Already up to date.\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "u9RAhs5b4vXY", + "colab_type": "text" + }, + "source": [ + "We will submit your Lab 1 using git at the next Lab." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "PPfGmFQI40HR", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-2/Lab_2_Solutions.ipynb b/Labs/Lab-2/Lab_2_Solutions.ipynb new file mode 100644 index 0000000..657d95d --- /dev/null +++ b/Labs/Lab-2/Lab_2_Solutions.ipynb @@ -0,0 +1,1198 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-2.ipynb", + "provenance": [], + "collapsed_sections": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "uk7yc0nadBGa", + "colab_type": "text" + }, + "source": [ + "# Lab 2\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-2/Lab-2.ipynb)\n", + "\n", + "## Submitting lab solutions\n", + "\n", + "At the end of the previous lab, you should have set up a \"Solutions\" directory in your Google Drive, with a fork of the class git repository that pull from Dr. Farbin's verison and pushes to your own fork. \n", + "\n", + "Unfortunately due to a typo in the previous lab, you probably forked the 2019 version of the gitlab repository for this course. Unless you noticed and corrected the error, you'll have to fork again.\n", + "\n", + "In addition, due to some problems with the setup in Google Colab, we will be submitting our solutions to your fork using the web interface. Instructions on how to use the command-line are in this notebook, but we suggest you do not follow them unless you are working in a jupyter notebook and not Google Colab." + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "OMNaOnRksNK3", + "colab_type": "text" + }, + "source": [ + "You may also choose to delete the fork from your GitHub account. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "J_R64sQDqv0A" + }, + "source": [ + "## Repeating last steps of Lab 1\n", + "\n", + "### Create your own fork\n", + "We will create a new fork where you can keep track and submit your work, following [these instructions](https://help.github.com/articles/fork-a-repo/).\n", + "\n", + "Goto to github.com and log in.\n", + "\n", + "Next, create a fork of the [2020 class repository](https://github.com/afarbin/DATA1401-Spring-2020). Click the link and press the \"Fork\" button on the top right. Select your repository as where you want to place the fork.\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "edTvE6rOqv0C" + }, + "source": [ + "### Make a local clone (Advanced)\n", + "\n", + "Before we get started, please mount your Google Drive using by clicking the file icon on the left, then clicking \"Mount Drive\", and following the instructions as you did in the previous lab.\n", + "\n", + "If you did complete Lab 1 and therefore created a 2019 fork and a local clone in you Google Drive, delete the local clone:\n", + "\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "2u6B-rfNr1wN", + "colab_type": "code", + "colab": {} + }, + "source": [ + "!rm -rf drive/My\\ Drive/Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "BDVI5nu8-2RH", + "colab_type": "text" + }, + "source": [ + "Now we will check out your fork in your Google Drive / Colab. If you will be doing everything on your own computer instead of Google Colab/Drive, you are welcome to install Git on your computer and perform the following steps (appropriately modified) on your computer instead.\n", + "\n", + "Start by listing the contents of your current directory." + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "e5tXg0f8qv0D", + "colab": {} + }, + "source": [ + "%cd /content/drive/My\\ Drive\n", + "!ls" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "WYsyYcg1qv0J" + }, + "source": [ + "Make a new directory:" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "Z7noY1hMqv0L", + "colab": {} + }, + "source": [ + "!mkdir Data-1401-Repo\n", + "%cd Data-1401-Repo" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "fwsBdTnYqv0Q" + }, + "source": [ + "From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n", + "\n", + "Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "colab_type": "code", + "id": "8w42MH6Jqv0S", + "colab": {} + }, + "source": [ + "# What you past here should look like:\n", + "#!git clone https://github.com/ 0:\n", + " return(a_set.intersection(b_set))\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "IJDf6ebYdBHV", + "colab_type": "code", + "outputId": "a6436b56-0339-44e7-efb9-8555eb36fc79", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "a = [1,2,5,7,9,10]\n", + "b = [1,3,4,7,8]\n", + "common_elements(a,b)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "{1, 7}" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 55 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "3vA7M9pldBHX", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* Write a function that reads takes a string and returns `True` if the string is a palindrome. (A palindrome is a string that reads the same forwards and backwards.)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "ncyMDzp6dBHX", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def pal(w):\n", + " rev_w = reversed(w)\n", + " if list(w)==list(rev_w):\n", + " print(\"The string is a palindrome\")\n", + " else:\n", + " print(\"The string is not a palidrome\")\n", + " \n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "v5cmVQ6MdBHZ", + "colab_type": "code", + "outputId": "bb0b573c-e44d-4e97-946d-3a0743e7cc8f", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "w = 'lool'\n", + "pal(w)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "The string is a palindrome\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "fT35xwandBHc", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Write a Rock-Paper-Scissors game function, that takes 2 strings, the inputs of player 1 and player 2, and output 1 or 2 corresponding to which player wins, or 0 if draw.\n", + "\n", + "Implement a Rock-Paper-Scissors game by soliciting input from 2 players, testing with this function, and repeating if there is a draw.\n", + "\n", + "Remember the rules:\n", + "\n", + "* Rock beats scissors\n", + "* Scissors beats paper\n", + "* Paper beats rock" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "6HGcQsY8zF3e", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#Write your solution here\n", + "p1score = 0\n", + "p2score = 0\n", + "\n", + "def compare(p1,p2):\n", + " global p1score\n", + " global p2score\n", + "\n", + " if p1==p2:\n", + " return(\"Its a draw\")\n", + " return compare(p1,p2)\n", + " elif p1=='r':\n", + " if p2=='s':\n", + " p1score+=1\n", + " return(\"Rock wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Paper wins, player 2 wins\")\n", + " elif p1=='p':\n", + " if p2=='r':\n", + " p1score+=1\n", + " return(\"Paper wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Scissors wins, player 2 wins\")\n", + " elif p1=='s':\n", + " if p2=='p':\n", + " p1score+=1\n", + " return(\"Scissors wins, player 1 wins\")\n", + " else:\n", + " p2score+=1\n", + " return(\"Rock wins, player 2 wins\")" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "ooR2ldZBdBHf", + "colab_type": "code", + "outputId": "22c16a71-0699-4397-a4f2-e71ecd963afb", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 425 + } + }, + "source": [ + "# Test your solution here\n", + "noWinner = 1\n", + "while noWinner: \n", + " print(\"This is rock, paper, scissors. Best 2 out of 3 wins.\")\n", + " player1=input(\"Player 1, choose rock (r), paper (p), or scissors (s): \")\n", + " player2=input(\"Player 2, choose rock (r), paper (p), or scissors (s): \")\n", + " print(compare(player1, player2))\n", + " print(\"Player1: \"+str(p1score)+\" points\")\n", + " print(\"Player2: \"+str(p2score)+\" points\")\n", + "\n", + " if p1score==2 or p2score==2:\n", + " noWinner = 0" + ], + "execution_count": 44, + "outputs": [ + { + "output_type": "stream", + "text": [ + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): s\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Its a draw\n", + "Player1: 0 points\n", + "Player2: 0 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): r\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Rock wins, player 1 wins\n", + "Player1: 1 points\n", + "Player2: 0 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): p\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Scissors wins, player 2 wins\n", + "Player1: 1 points\n", + "Player2: 1 points\n", + "This is rock, paper, scissors. Best 2 out of 3 wins.\n", + "Player 1, choose rock (r), paper (p), or scissors (s): r\n", + "Player 2, choose rock (r), paper (p), or scissors (s): s\n", + "Rock wins, player 1 wins\n", + "Player1: 2 points\n", + "Player2: 1 points\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "dJQzXNKzdBHh", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Write a function that takes a integer `n` as input and \n", + "outputs a list of the first `n` Fibonnaci numbers.\n", + "\n", + "The Fibonnaci seqence is a sequence of numbers where the next number in the sequence is the sum of the previous two numbers in the sequence. The sequence looks like this: 1, 1, 2, 3, 5, 8, 13, …)" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "G_4ooRXTdBHh", + "colab_type": "code", + "outputId": "9a435058-169c-4f1e-a493-aded562c06ad", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "# Write you solution here\n", + "def fibseq(n):\n", + " if n <=1:\n", + " return n\n", + " else:\n", + " return(fibseq(n-1)+fibseq(n-2))\n", + "nn = int(input(\"How many terms?\"))\n", + "if nn <=0:\n", + " print(\"Invalid input, enter positive integer\")\n", + "else:\n", + " print(\"Fibonacci sequence: \")\n", + " for i in range(nn):\n", + " print(fibseq(i))\n" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "How many terms?7\n", + "Fibonacci sequence: \n", + "0\n", + "1\n", + "1\n", + "2\n", + "3\n", + "5\n", + "8\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "rzK5FskJdBHj", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "q6c_AskadBHl", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Write a function that takes a string of consisting of several words and returns a string that reverses the order of the words.\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "aJdXX6FHdBHl", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def revwords(s):\n", + " r = s.split()\n", + " r.reverse()\n", + " end=\" \".join(r)\n", + " return end\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "nQyhnLZ_dBHn", + "colab_type": "code", + "outputId": "95b49c24-4ebe-4354-eaef-adc44f909cf7", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "s = \"the sky is blue\"\n", + "revwords(s)" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "'blue is sky the'" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 64 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "NFSmRaSydBHq", + "colab_type": "text" + }, + "source": [ + "*Exercise 10:* Write a guessing game program that will repeatedly guess a number that the users picks, with the user indicating higher or lower, until it correctly guesses the number." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Ie2E1JzCdBHr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "import random\n", + "def comp_guess():\n", + " high=100\n", + " low=1\n", + " guesses = []\n", + " user_num=int(input(\"Choose a number 1-100 for the computer to guess: \"))\n", + "\n", + " while True:\n", + " compg=random.randint(low, high)\n", + " if compg in guesses:\n", + " compg = random.randint(low,high)\n", + " continue\n", + " if compg > user_num:\n", + " high=compg\n", + " guesses.append(compg)\n", + " print(str(compg)+\" is too high\")\n", + " elif compg" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 15 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "kOJ9dpeWMSSQ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-3/Lab_3_Solutions.ipynb b/Labs/Lab-3/Lab_3_Solutions.ipynb new file mode 100644 index 0000000..125ab7b --- /dev/null +++ b/Labs/Lab-3/Lab_3_Solutions.ipynb @@ -0,0 +1,1334 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "name": "python3", + "display_name": "Python 3" + }, + "colab": { + "name": "Copy of Lab-3.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "IdltFBGZeATV", + "colab_type": "text" + }, + "source": [ + "# Lab 3- Tic Tac Toe\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-3/Lab-3.ipynb)\n", + "\n", + "In this lab your will build a n x n Tic Tac Toe game. As you do the exercises, make sure your solutions work for any size Tic Tac Toe game. " + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "o1g8qjmTeATY", + "colab_type": "text" + }, + "source": [ + "*Exercise 1:* Write a function that creates an n by n matrix (of list of lists) which will represent the state of a Tie Tac Toe game. Let 0, 1, and 2 represent empty, \"X\", or \"O\".\n" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "K8u0WdnrfPMW", + "colab_type": "code", + "colab": {} + }, + "source": [ + "empty=0\n", + "X=1\n", + "O=2\n", + "\n", + "def size(message):\n", + " while True:\n", + " try:\n", + " userin=int(input(message))\n", + " except ValueError:\n", + " print(\"Invalid. Size must be an integer: \")\n", + " continue\n", + " else:\n", + " return userin\n", + " break\n", + "\n", + "def print_board(board):\n", + " for count, row in enumerate(board):\n", + " print(count, row)\n", + "\n", + "def board_game():\n", + " print(\"Tic Tac Toe Game\")\n", + " board_size=size(\"Enter desired size of nxn game board: \")\n", + "\n", + " \n", + " board=[[empty]*board_size for i in range(board_size)]\n", + "\n", + " print_board(board)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "gGbJsvxPiYtr", + "colab_type": "code", + "outputId": "1c49b60f-8843-493c-8445-27ee52fe3794", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + } + }, + "source": [ + "board_game()" + ], + "execution_count": 28, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Tic Tac Toe Game\n", + "Enter desired size of nxn game board: 3\n", + "0 [0, 0, 0]\n", + "1 [0, 0, 0]\n", + "2 [0, 0, 0]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "mrSlynpEeATg", + "colab_type": "text" + }, + "source": [ + "*Exercise 2:* Write a function that takes a `n` by `n` matrix representing a tic-tac-toe game, and returns -1, 0, 1, or 2 indicating the game is incomplete, the game is a draw, player 1 has won, or player 2 has one, respectively. Here are some example inputs you can use to test your code:" + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "UqxHeWqdeATh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "winner_is_2 = [[2, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "winner_is_1 = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "winner_is_also_1 = [[0, 1, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 1]]\n", + "\n", + "no_winner = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 2]]\n", + "\n", + "also_no_winner = [[1, 2, 0],\n", + "\t[2, 1, 0],\n", + "\t[2, 1, 0]]\n", + "\n", + "#extra tests for incomplete games\n", + "incomplete_game1 = [[1, 2, 0],\n", + " [0, 2, 0],\n", + "\t\t\t\t\t\t\t\t\t\t[1, 0, 0]]\n", + "\n", + "incomplete_game2 = [[1, 2, 0],\n", + " [2, 2, 0],\n", + "\t\t\t\t\t\t\t\t\t\t[1, 1, 0]]\n", + "\n", + "incomplete_game3 = [[0, 2, 1],\n", + " [2, 0, 2],\n", + "\t\t\t\t\t\t\t\t\t\t[1, 1, 0]]\n", + "\n", + "incomplete_game4 = [[1, 2, 1],\n", + " [2, 1, 2],\n", + "\t\t\t\t\t\t\t\t\t\t[0, 0, 0]]\n", + "\n", + "diag_win_1 = [[1, 2, 1],\n", + " [2, 1, 2],\n", + "\t\t\t\t\t\t [0, 2, 1]]" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "63chiBZzbrHq", + "colab_type": "code", + "colab": {} + }, + "source": [ + "incomplete_game=-1\n", + "draw_game=0\n", + "p1_wins=1\n", + "p2_wins=2\n", + "result_dict = {-1:\"Incomplete game\", 0:\"Draw game\", 1:\"Player 1 wins\",2:\"Player 2 wins\"}\n", + "\n", + "def row_win(current_board, player):\n", + " for i in range(len(current_board)):\n", + " is_winner=True\n", + "\n", + " for j in range(len(current_board)):\n", + " if (current_board[i][j] != player):\n", + " is_winner=False\n", + " continue\n", + " if is_winner == True:\n", + " return is_winner\n", + " return is_winner \n", + "\n", + "\n", + "def column_win(current_board, player):\n", + " for i in range(len(current_board)):\n", + " is_winner=True\n", + "\n", + " for j in range(len(current_board)):\n", + " if (current_board[j][i] != player):\n", + " is_winner=False\n", + " continue\n", + " if is_winner == True:\n", + " return is_winner\n", + " return is_winner\n", + "\n", + "\n", + "def diagonal_win(current_board, player):\n", + " is_winner=True\n", + "\n", + " for i in range(len(current_board)):\n", + " if (current_board[i][i] != player):\n", + " is_winner=False\n", + " if (is_winner == True):\n", + " return is_winner\n", + " \n", + " is_winner=True\n", + " x = len(current_board)-1\n", + " for y in range(len(current_board)):\n", + " if (current_board[x][y] != player):\n", + " is_winner=False\n", + " x-=1\n", + "\n", + "def full_board(current_board):\n", + " for x in range(len(current_board)):\n", + " for y in range(len(current_board)):\n", + " if (current_board[x][y] == empty):\n", + " return False\n", + " return True\n", + "\n", + "\n", + "def survey_board(current_board):\n", + " if (column_win(current_board,1) or\n", + " row_win(current_board,1) or\n", + " diagonal_win(current_board,1)):\n", + " return p1_wins\n", + "\n", + " if (column_win(current_board,2) or\n", + " row_win(current_board,2) or\n", + " diagonal_win(current_board,2)):\n", + " return p2_wins\n", + "\n", + " if (full_board(current_board)):\n", + " return draw_game\n", + " \n", + " return incomplete_game" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "8X9xhHH_od_t", + "colab_type": "code", + "outputId": "053b8aa4-5ad5-4034-840b-15a9f918de06", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + } + }, + "source": [ + "print(\"P2 should win: \"+result_dict.get(survey_board(winner_is_2)))\n", + "print(\"P1 should win: \"+result_dict.get(survey_board(winner_is_1)))\n", + "print(\"P1 should win: \"+result_dict.get(survey_board(winner_is_also_1)))\n", + "print(\"Should be draw game: \"+result_dict.get(survey_board(no_winner)))\n", + "print(\"Should be incomplete: \"+result_dict.get(survey_board(also_no_winner)))\n", + "print(\"Should be incomplete: \"+result_dict.get(survey_board(incomplete_game1)))\n", + "print(\"Should be incomplete: \"+result_dict.get(survey_board(incomplete_game2)))\n", + "print(\"Should be incomplete: \"+result_dict.get(survey_board(incomplete_game3)))\n", + "print(\"Should be incomplete: \"+result_dict.get(survey_board(incomplete_game4)))\n", + "print(\"P1 should win: \"+result_dict.get(survey_board(diag_win_1)))" + ], + "execution_count": 81, + "outputs": [ + { + "output_type": "stream", + "text": [ + "P2 should win: Player 2 wins\n", + "P1 should win: Player 1 wins\n", + "P1 should win: Player 1 wins\n", + "Should be draw game: Incomplete game\n", + "Should be incomplete: Incomplete game\n", + "Should be incomplete: Incomplete game\n", + "Should be incomplete: Incomplete game\n", + "Should be incomplete: Incomplete game\n", + "Should be incomplete: Incomplete game\n", + "P1 should win: Player 1 wins\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "oIv8fri-eATk", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "JrtUFdRCeATo", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "flxiNVB8eATr", + "colab_type": "text" + }, + "source": [ + "*Exercise 3:* Write a function that takes 2 integers `n` and `m` as input and draws a `n` by `m` game board. For example the following is a 3x3 board:\n", + "```\n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " | | | | \n", + " --- --- --- \n", + " ```" + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "KZJMN7T3eATr", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def draw_board(bm,bn):\n", + " for index in range(bm):\n", + " print(\" ---\"*bm)\n", + " print(\"| \"*(bn+1))\n", + " print(\" ---\"*bm)\n", + " \n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "NpQ-xi9ceATu", + "colab_type": "code", + "outputId": "76305be1-adc0-4b50-b8df-39329b230a92", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + } + }, + "source": [ + "# Test your solution here\n", + "bsize_m= int(input(\"Rows: \"))\n", + "bsize_n= int(input(\"Columns: \"))\n", + "\n", + "draw_board(bsize_m, bsize_n)" + ], + "execution_count": 58, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Rows: 3\n", + "Columns: 3\n", + " --- --- ---\n", + "| | | | \n", + " --- --- ---\n", + "| | | | \n", + " --- --- ---\n", + "| | | | \n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "nPv2OKYyeATw", + "colab_type": "text" + }, + "source": [ + "*Exercise 4:* Modify exercise 3, so that it takes a matrix of the form from exercise 2 and draws a tic-tac-tie board with \"X\"s and \"O\"s. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "luYy_8rmeATx", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "symbol_dict = { 0:' ', 1:'X', 2:'O'}\n", + "\n", + "def draw_niceboard(current_board):\n", + " for index in range(len(current_board)):\n", + " print(\" ---\"*len(current_board))\n", + " line=\"|\"\n", + " for y in range(len(current_board)):\n", + " line = line + \" \" + symbol_dict.get(current_board[index][y]) + \" |\"\n", + " print(line)\n", + " print(\" ---\" * len(current_board))\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "FzRLtrmreAT0", + "colab_type": "code", + "outputId": "f8d239d8-6297-443e-cb18-a58ac7503c95", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 612 + } + }, + "source": [ + "# Test your solution here\n", + "draw_niceboard(winner_is_2)\n", + "draw_niceboard(winner_is_1)\n", + "draw_niceboard(winner_is_also_1)\n", + "draw_niceboard(no_winner)\n", + "draw_niceboard(also_no_winner)" + ], + "execution_count": 60, + "outputs": [ + { + "output_type": "stream", + "text": [ + " --- --- ---\n", + "| O | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| | X | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | X |\n", + " --- --- ---\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | O |\n", + " --- --- ---\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n", + "| O | X | |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "KwrIuJC9eAT2", + "colab_type": "text" + }, + "source": [ + "*Exercise 5:* Write a function that takes a game board, player number, and `(x,y)` coordinates and places \"X\" or \"O\" in the correct location of the game board. Make sure that you only allow filling previously empty locations. Return `True` or `False` to indicate successful placement of \"X\" or \"O\"." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "yDFMZVhFeAT3", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def modify_board(current_board, player, bx, by):\n", + " if (bx < 0 or bx > len(current_board)-1):\n", + " print(\"Invalid, out of bounds\")\n", + " return False\n", + "\n", + " if (by < 0 or by > len(current_board)-1):\n", + " print(\"Invalid, out of bounds\")\n", + " return False\n", + "\n", + " if(current_board[bx][by] != empty):\n", + " print(\"Space already occupied\")\n", + " return False\n", + "\n", + " if (player == 1):\n", + " current_board[bx][by] = X;\n", + " elif (player == 2):\n", + " current_board[bx][by] = O;\n", + " else:\n", + " print(\"Only player 1 or 2\")\n", + " return False\n", + "\n", + " return True" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "33kz9PJLeAT6", + "colab_type": "code", + "outputId": "5d1c0e6e-beca-467c-e72e-6252997601fa", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 306 + } + }, + "source": [ + "# Test your solution here\n", + "incomplete_game5 = [ [1, 2, 0],\n", + " [0, 2, 0],\n", + " [1, 0, 0]]\n", + "valid_input=False\n", + "draw_niceboard(incomplete_game5)\n", + "\n", + "while valid_input == False:\n", + " which_player = int(input(\"Which player: \"))\n", + " x_coord=int(input(\"X-coordinate: \"))\n", + " y_coord=int(input(\"Y-coordinate: \"))\n", + "\n", + " valid_input=modify_board(incomplete_game5, which_player, x_coord, y_coord)\n", + "\n", + "\n", + "draw_niceboard(incomplete_game5)" + ], + "execution_count": 62, + "outputs": [ + { + "output_type": "stream", + "text": [ + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| | O | |\n", + " --- --- ---\n", + "| X | | |\n", + " --- --- ---\n", + "Which player: 1\n", + "X-coordinate: 2\n", + "Y-coordinate: 2\n", + " --- --- ---\n", + "| X | O | |\n", + " --- --- ---\n", + "| | O | |\n", + " --- --- ---\n", + "| X | | X |\n", + " --- --- ---\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "4c9QmfB7eAT8", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* Modify Exercise 4 to show column and row labels so that players can specify location using \"A2\" or \"C1\"." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "o9gbzwSAeAT9", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "row_names=(\"ABCDEFGHIJKLMNOPQRSTUVWXYZ\")\n", + "row_map=dict(zip(row_names, range(len(row_names))))\n", + "column_names=list(map(str, range(1,len(row_names)+1)))\n", + "column_map=dict(zip(column_names,range(len(row_names))))\n", + "\n", + "def draw_niceboard(current_board):\n", + " for index in range(len(current_board)):\n", + " print(\" \"+column_names[index], end=\" \")\n", + " print()\n", + "\n", + " for index in range(len(current_board)):\n", + " print(\" \",\"--- \" * len(current_board))\n", + "\n", + " line = row_names[index]+\"|\"\n", + " for y in range(len(current_board)):\n", + " line = line + \" \" + symbol_dict.get(current_board[index][y]) + \" |\"\n", + " print(line)\n", + "\n", + " print(\" \",\"--- \" * len(current_board))\n", + " " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "nLy4C0W1eAT_", + "colab_type": "code", + "outputId": "fcb2655c-6ccd-4f7d-8d45-5707e998c4ec", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 289 + } + }, + "source": [ + "# Test your solution here\n", + "draw_niceboard(winner_is_2)\n", + "draw_niceboard(winner_is_1)\n" + ], + "execution_count": 64, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- --- \n", + "A| O | O | |\n", + " --- --- --- \n", + "B| O | X | |\n", + " --- --- --- \n", + "C| O | X | X |\n", + " --- --- --- \n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | O | |\n", + " --- --- --- \n", + "B| O | X | |\n", + " --- --- --- \n", + "C| O | X | X |\n", + " --- --- --- \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "T1ZczV45eAUC", + "colab_type": "text" + }, + "source": [ + "*Exercise 7:* Write a function that takes a board, player number, and location specified as in exercise 6 and then calls exercise 5 to correctly modify the board. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "zUBtjAqleAUD", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def parse_location(cellStr):\n", + " if not isinstance(cellStr, str):\n", + " print(\"Bad input. Location must be a string\")\n", + " return -1,-1,0\n", + " if len(cellStr) !=2:\n", + " print(\"Bad input, Location must be a string\")\n", + " return -1,-1,0\n", + "\n", + " row=cellStr[0].upper()\n", + " col=cellStr[1].upper()\n", + "\n", + " if not row in row_names:\n", + " print(\"Invalid row\")\n", + " return -1,-1,0\n", + " if not col in column_names:\n", + " print(\"Invalid column\")\n", + "\n", + " return row_map[row],column_map[col],1\n", + "\n", + "\n", + "def p_move(current_board, player, cellStr):\n", + " cell_coord=parse_location(cellStr)\n", + " if (cell_coord[2]==1):\n", + " return modify_board(current_board, player, cell_coord[0], cell_coord[1])\n", + " else:\n", + " return False" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "_5UvOPazeAUE", + "colab_type": "code", + "outputId": "1aaf05dd-15bb-43b9-fd66-f1dd14b25da5", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 476 + } + }, + "source": [ + "# Test your solution here\n", + "incomplete_game5 = [[1, 2, 0],\n", + " [0, 2, 0],\n", + "\t\t\t\t\t\t\t\t\t\t[1, 0, 0]]\n", + "\n", + "valid_input=False\n", + "draw_niceboard(incomplete_game5)\n", + "\n", + "while valid_input == False:\n", + " which_player = int(input(\"Which player: \"))\n", + " cell_choice=str(input(\"Choose cell location: \"))\n", + "\n", + " valid_input=p_move(incomplete_game5, which_player, cell_choice)\n", + "\n", + "\n", + "draw_niceboard(incomplete_game5)" + ], + "execution_count": 66, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- --- \n", + "A| X | O | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | |\n", + " --- --- --- \n", + "Which player: 1\n", + "Choose cell location: a1\n", + "Space already occupied\n", + "Which player: 2\n", + "Choose cell location: 1\n", + "Bad input, Location must be a string\n", + "Which player: 3\n", + "Choose cell location: c2\n", + "Only player 1 or 2\n", + "Which player: 1\n", + "Choose cell location: c3\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | O | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | X |\n", + " --- --- --- \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "venZ6-PIeAUG", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Write a function is called with a board and player number, takes input from the player using python's `input`, and modifies the board using your function from exercise 7. Note that you should keep asking for input until you have gotten a valid input that results in a valid move." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "pDJmX7AFeAUH", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def player_turn(current_board, player):\n", + " valid_input=False\n", + "\n", + " while valid_input == False:\n", + " cell_choice=str(input(\"Player \"+str(player)+\" choose cell location: \"))\n", + "\n", + " valid_input=p_move(current_board, player, cell_choice)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "JEVCMoIueAUJ", + "colab_type": "code", + "outputId": "4ac13859-e0e5-4711-e30a-762f06af9355", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 374 + } + }, + "source": [ + "# Test your solution here\n", + "incomplete_game5 = [[1, 2, 0],\n", + " [0, 2, 0],\n", + "\t\t\t\t\t\t\t\t\t\t[1, 0, 0]]\n", + "\n", + "\n", + "draw_niceboard(incomplete_game5)\n", + "player_turn(incomplete_game5,1)\n", + "draw_niceboard(incomplete_game5)" + ], + "execution_count": 68, + "outputs": [ + { + "output_type": "stream", + "text": [ + " 1 2 3 \n", + " --- --- --- \n", + "A| X | O | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | |\n", + " --- --- --- \n", + "Player 1 choose cell location: a1\n", + "Space already occupied\n", + "Player 1 choose cell location: b2\n", + "Space already occupied\n", + "Player 1 choose cell location: c3\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | O | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | X |\n", + " --- --- --- \n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "4e28CqQBeAUL", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Use all of the previous exercises to implement a full tic-tac-toe game, where an appropriate board is drawn, 2 players are repeatedly asked for a location coordinates of where they wish to place a mark, and the game status is checked until a player wins or a draw occurs." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "-3fsvGvSeAUM", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "def alt_player(player):\n", + " return 2 if player==1 else 1\n", + "\n", + "def tic_tac_toe():\n", + " player = 2\n", + "\n", + " print(\"Tic Tac Toe Game\")\n", + " board_size=size(\"Enter desired size of nxn game board: \")\n", + " gameboard=[[empty]*board_size for i in range(board_size)]\n", + "\n", + " draw_niceboard(gameboard)\n", + "\n", + " while (survey_board(gameboard)==incomplete_game):\n", + " player = alt_player(player)\n", + " player_turn(gameboard, player)\n", + " draw_niceboard(gameboard)\n", + " \n", + " print(result_dict.get(survey_board(gameboard)))" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "DujbpnQ6eAUO", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "5a4c1826-a252-4687-fc69-c2df7050eee3" + }, + "source": [ + "# Test your solution here\n", + "tic_tac_toe()" + ], + "execution_count": 85, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Tic Tac Toe Game\n", + "Enter desired size of nxn game board: 3\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| | | |\n", + " --- --- --- \n", + "B| | | |\n", + " --- --- --- \n", + "C| | | |\n", + " --- --- --- \n", + "Player 1 choose cell location: a1\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | | |\n", + " --- --- --- \n", + "B| | | |\n", + " --- --- --- \n", + "C| | | |\n", + " --- --- --- \n", + "Player 2 choose cell location: b2\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| | | |\n", + " --- --- --- \n", + "Player 1 choose cell location: a2\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | X | |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| | | |\n", + " --- --- --- \n", + "Player 2 choose cell location: a3\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | X | O |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| | | |\n", + " --- --- --- \n", + "Player 1 choose cell location: c1\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | X | O |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | |\n", + " --- --- --- \n", + "Player 2 choose cell location: c3\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | X | O |\n", + " --- --- --- \n", + "B| | O | |\n", + " --- --- --- \n", + "C| X | | O |\n", + " --- --- --- \n", + "Player 1 choose cell location: b1\n", + " 1 2 3 \n", + " --- --- --- \n", + "A| X | X | O |\n", + " --- --- --- \n", + "B| X | O | |\n", + " --- --- --- \n", + "C| X | | O |\n", + " --- --- --- \n", + "Player 1 wins\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "y91406TXeAUQ", + "colab_type": "text" + }, + "source": [ + "*Exercise 10:* Test that your game works for 5x5 Tic Tac Toe. " + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "cuF2_5DIeAUQ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "b980d191-5d82-4c57-fc47-6abd58213c0e" + }, + "source": [ + "# Test your solution here\n", + "tic_tac_toe()" + ], + "execution_count": 86, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Tic Tac Toe Game\n", + "Enter desired size of nxn game board: 5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| | | | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| | | | | |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: c3\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| | | | | |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: e1\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: 35\n", + "Invalid row\n", + "Player 1 choose cell location: e5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: a1\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: c1\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| X | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: a3\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| X | | X | | |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: c5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| X | | X | | X |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: c2\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: a5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | X |\n", + " --- --- --- --- --- \n", + "B| | | | | |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: b2\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | X |\n", + " --- --- --- --- --- \n", + "B| | O | | | |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | | | | |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: d5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | X |\n", + " --- --- --- --- --- \n", + "B| | O | | | |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | | | | X |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 2 choose cell location: d2\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | X |\n", + " --- --- --- --- --- \n", + "B| | O | | | |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | O | | | X |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 choose cell location: b5\n", + " 1 2 3 4 5 \n", + " --- --- --- --- --- \n", + "A| O | | O | | X |\n", + " --- --- --- --- --- \n", + "B| | O | | | X |\n", + " --- --- --- --- --- \n", + "C| X | O | X | | X |\n", + " --- --- --- --- --- \n", + "D| | O | | | X |\n", + " --- --- --- --- --- \n", + "E| O | | | | X |\n", + " --- --- --- --- --- \n", + "Player 1 wins\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "deletable": true, + "editable": true, + "id": "6Ty40YsZeAUS", + "colab_type": "text" + }, + "source": [ + "*Exercise 11: (Extra Credit)* Develop a version of the game where one player is the computer. Note that you don't need to do an extensive seach for the best move. You can have the computer simply protect against loosing and otherwise try to win with straight or diagonal patterns." + ] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "wN31QYlAeAUT", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Write you solution here\n", + "import random" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "deletable": true, + "editable": true, + "id": "IWzQgG1veAUV", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Test your solution here" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-4/Lab_4_Solutions.ipynb b/Labs/Lab-4/Lab_4_Solutions.ipynb new file mode 100644 index 0000000..e5431f2 --- /dev/null +++ b/Labs/Lab-4/Lab_4_Solutions.ipynb @@ -0,0 +1,1890 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.1" + }, + "colab": { + "name": "Copy of Lab-4.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "NpJwRQ5jR_UE", + "colab_type": "text" + }, + "source": [ + "## Lab 4\n", + "\n", + "[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github//afarbin/DATA1401-Spring-2020/blob/master/Labs/Lab-4/Lab-4.ipynb)\n", + "\n", + "In this lab we will become familiar with distributions, histograms, and functional programming. \n", + "\n", + "\n", + "### Uniform Distribution\n", + "Lets start with generating some fake random data. You can get a random number between 0 and 1 using the python random module as follow:" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "4X73PSMdT2Dz", + "colab_type": "code", + "outputId": "141ac6db-19df-4af9-d132-5a1869a61007", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 122 + } + }, + "source": [ + "from google.colab import drive\n", + "drive.mount('/content/drive')" + ], + "execution_count": 0, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Go to this URL in a browser: https://accounts.google.com/o/oauth2/auth?client_id=947318989803-6bn6qk8qdgf4n4g3pfee6491hc0brc4i.apps.googleusercontent.com&redirect_uri=urn%3aietf%3awg%3aoauth%3a2.0%3aoob&response_type=code&scope=email%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdocs.test%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive%20https%3a%2f%2fwww.googleapis.com%2fauth%2fdrive.photos.readonly%20https%3a%2f%2fwww.googleapis.com%2fauth%2fpeopleapi.readonly\n", + "\n", + "Enter your authorization code:\n", + "··········\n", + "Mounted at /content/drive\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "YqXRLT7NR_UG", + "colab_type": "code", + "outputId": "2d062356-783a-4848-e806-da1689876380", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "import random\n", + "x=random.random()\n", + "print(\"The Value of x is\", x)" + ], + "execution_count": 3, + "outputs": [ + { + "output_type": "stream", + "text": [ + "The Value of x is 0.10057148881070455\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "Ker61ylkR_UK", + "colab_type": "text" + }, + "source": [ + "Everytime you call random, you will get a new number.\n", + "\n", + "*Exercise 1:* Using random, write a function `generate_uniform(N, mymin, mymax)`, that returns a python list containing N random numbers between specified minimum and maximum value. Note that you may want to quickly work out on paper how to turn numbers between 0 and 1 to between other values. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "NzxgWIMRR_UL", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def generate_uniform(N,x_min,x_max):\n", + " out = []\n", + "\n", + " for i in range(N):\n", + " out.append(random.randrange(x_min,x_max))\n", + "\n", + "\n", + " ### BEGIN SOLUTION\n", + "\n", + " # Fill in your solution here \n", + " \n", + " ### END SOLUTION\n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "YU1ceSAuR_UO", + "colab_type": "code", + "outputId": "acfae7aa-e7fb-46c1-e705-951d8852f185", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 139 + } + }, + "source": [ + "# Test your solution here\n", + "data=generate_uniform(1000,-10,10)\n", + "print(data)\n", + "print(\"Data Type:\", type(data))\n", + "print(\"Data Length:\", len(data))\n", + "if len(data)>0: \n", + " print(\"Type of Data Contents:\", type(data[0]))\n", + " print(\"Data Minimum:\", min(data))\n", + " print(\"Data Maximum:\", max(data))" + ], + "execution_count": 5, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[9, 7, -8, 6, -9, -10, 8, 5, 3, -1, 9, 2, -3, 1, -5, -9, -7, -2, 1, -9, 0, 6, 1, 8, -8, 1, 1, -8, 2, 3, -9, -5, 0, -4, 4, 8, -3, -6, 6, -3, 8, 1, -3, 5, -10, -8, -10, 1, -1, -5, 5, 4, 1, 8, 9, -10, -8, -7, -1, -8, -9, -2, -1, 0, -4, -4, 5, 9, 5, -7, -1, 5, -8, 3, -4, -6, -10, -10, 4, -9, 3, 2, 9, 8, -1, 3, 2, -8, 4, 6, -2, -1, -10, 4, -10, 1, 9, -5, -2, 2, -9, 5, 8, 0, 4, 0, -9, -9, -9, 1, 2, -8, 8, -7, 5, 4, 6, 0, -2, 0, -7, -5, 9, -7, 4, 4, 9, -1, 3, 0, -1, 7, -1, -8, -6, -7, -10, 4, -3, -7, -8, 2, -5, -4, -6, 7, 9, 6, -9, -8, 1, -10, -2, -3, -8, 3, 7, 9, 6, -2, -8, -8, 4, -5, -4, -7, 3, -8, 0, 9, -7, 6, 1, 1, -7, -4, -10, 3, 4, -5, -10, 4, -4, -1, -5, 4, -9, -5, 5, -10, -6, 0, -3, -4, 4, -1, 0, 9, -10, -4, 2, 1, -9, -7, 0, -1, -2, -10, 4, 8, -1, -2, 0, -5, -2, 0, 4, 1, -6, -4, -7, -9, -10, 5, -2, 9, 4, -10, -3, -2, -2, 1, 6, 1, 4, -3, 5, 6, -8, -10, -10, -3, 4, -1, 2, 8, -2, -4, 1, 5, 8, 6, -9, -4, -8, 9, -9, -4, 9, -3, -7, -6, -5, 2, 9, -2, 8, 5, -5, -3, 4, 0, -1, 0, 7, 8, -5, -6, 1, -8, -1, 9, 2, -6, 6, 9, -10, 3, 2, -5, 7, 8, 1, 5, 6, -6, 5, 7, 4, 9, 3, -9, -5, -10, -9, -10, 0, -1, -3, -6, -5, 9, 9, -1, 0, -4, -2, -6, -1, -3, 1, 9, -7, 8, 6, -4, 5, -3, -6, 1, -6, 2, -7, 3, -8, -10, -8, -5, -6, 8, 4, 5, -10, 9, 1, 9, 7, 6, 1, 7, -3, 3, -3, 6, 1, -8, 8, 6, -4, 8, -7, -2, -9, -3, -1, 4, -9, -6, 7, -10, -6, 9, -9, -5, -10, 1, 9, -4, -4, -3, -1, 2, 8, 4, 5, -6, 8, 3, -3, -2, 5, 1, -2, 7, -2, -1, 4, 5, -8, 8, 6, -8, -10, -10, -6, -7, -8, 9, -2, 5, -1, -6, -8, -2, 6, 0, 5, 1, -10, 6, -3, -5, -1, -5, 0, 2, -5, -5, 8, -8, -6, 5, 2, -7, 8, 4, 3, -1, -10, 9, 7, 3, -6, -4, 0, 2, -8, 5, 1, 2, -9, 5, -1, 5, 6, -5, 5, -2, 2, 0, -9, 2, -1, -9, -2, -1, 6, -9, 7, 1, -3, -7, 5, -9, -2, -8, 4, -6, -4, 4, 8, -1, -4, -9, 4, -4, 5, 9, -6, 3, -2, -6, -6, 9, -2, -5, 8, -5, 6, 0, -6, -3, 1, -10, -5, 9, -8, -9, -2, -8, 3, 5, -9, 7, -3, 0, -8, 6, -4, 0, -9, 1, -6, -3, 1, -8, 0, -5, 9, 9, 7, -10, -8, 3, -5, 0, -10, -9, 8, -8, -2, -9, 4, -9, -5, -4, 5, 8, 1, 4, 1, 4, -10, 4, -10, -4, 6, 5, -3, -1, 4, -2, -1, 5, -3, 9, 1, 4, -1, -5, 8, -5, 5, -1, 5, -3, -2, 2, -4, -10, 5, -4, 3, 6, -3, -10, -8, -6, 0, 4, 7, 4, 4, 8, 7, 1, -4, -7, -2, -6, 9, 9, 0, -3, 6, 0, -4, 5, -2, -8, 2, 0, -2, 0, -4, -10, 1, 6, 9, 1, 8, -8, -9, -9, -4, 8, 9, -4, 1, -6, -6, -2, 5, -3, -3, -7, -1, 9, 3, 9, 7, 8, 5, -8, -4, 6, 3, 7, 4, 9, -8, 6, 9, -8, -6, -7, 8, -7, -4, 3, -9, -7, -6, -9, 6, 0, 3, 3, -1, -2, -9, -5, -8, -1, 5, 1, 0, -4, -9, 5, 2, -7, 3, -5, -8, 2, -1, -4, -1, -1, 4, 3, -9, -5, 5, 6, -8, -5, -6, -8, 8, -4, 2, 6, 7, -1, 1, 4, 2, 6, 4, -10, 6, -5, 2, 1, 8, 4, -7, 8, 1, -6, 2, 4, -10, -1, 5, -1, -8, -7, -3, 3, 2, 1, -5, -7, -4, 1, -7, 0, -3, 0, -7, 5, -2, 1, 1, 8, 7, -1, -6, -7, -1, 6, -6, -10, -7, 2, -10, -3, 9, -6, -8, 4, 1, -4, -5, -2, -3, -5, 1, 7, 1, -1, 8, -7, -4, 3, -6, 8, 8, -7, 1, -7, 3, 5, -9, -10, -8, -4, 4, -9, -7, 1, -6, -7, 6, -5, 4, -9, -10, 8, -1, -3, 1, -6, -2, 7, 5, -6, -10, 5, -1, 5, 2, 4, -8, -5, -7, 6, 2, -10, 7, 6, -3, 2, 8, -3, 4, 4, 0, 6, 9, 2, 8, 9, -8, -4, 9, -4, -9, 5, 2, 7, -3, -8, 1, -2, 1, -4, -6, -10, -7, 0, -10, 1, 9, 2, 0, 2, 3, 7, 6, 1, -6, 9, -2, -9, -1, 9, 3, -8, -5, 0, -10, -10, -2, 4, -1, -5, -1, 8, -4, -4, 4, -9, -8, -7, 3, 2, 2, -9, -5, -2, -5, 8, 6, 7, 4, -9, -2, -6, 1, -9, -1, 4, -8, 8, -2, 2, 3, -2, 2, -7, -7, 4, 8, 3, -7, 5, -4, -1, 4, 1, -6, 3, -6, 8, -5, 6, 2, -4, 4, -3, -9, 3, -3, -8, 9, 8, 9, 0, -9, 7, -6, 0, -3, -10, -9, 0, -4, 9, -1, -2, -9, -7, -8, 9, -9, 3, 2, 9, 3, -8, 2, 1, 6, 3, 1, 2, 2, 0, 1, 5, -8, -2, -2, -8, -7, -10, 8, -9, 3, -1, 9, -3, 9, -8, 3, -4, 3, 2, 1, 9, 1, 0, 1, 8, -8, -3]\n", + "Data Type: \n", + "Data Length: 1000\n", + "Type of Data Contents: \n", + "Data Minimum: -10\n", + "Data Maximum: 9\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "6C1BlyXQR_UR", + "colab_type": "text" + }, + "source": [ + "*Exercise 2a:* \n", + "Write a function that computes the mean of values in a list." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "joY08GajR_US", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def mean(Data):\n", + " m=0.\n", + " m=sum(Data)/len(Data)\n", + " \n", + " \n", + " ### BEGIN SOLUTION\n", + "\n", + " # Fill in your solution here \n", + " \n", + " ### END SOLUTION\n", + " \n", + " return m" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3Xap_PV3R_UV", + "colab_type": "code", + "outputId": "87234dad-07c6-460b-9f49-d465177508f1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "print(\"Mean of Data:\", mean(data))" + ], + "execution_count": 91, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Mean of Data: -0.689\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "SwH2z0qTR_UY", + "colab_type": "text" + }, + "source": [ + "*Exercise 2b:* \n", + "Write a function that computes the variance of values in a list." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LgrjlNaeR_UZ", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Skeleton\n", + "def variance(Data):\n", + " m=0.\n", + " mean=sum(Data)/len(Data)\n", + "\n", + " m=sum((i - mean) ** 2 for i in Data) / len(Data)\n", + " \n", + "\n", + " ### BEGIN SOLUTION\n", + "\n", + " # Fill in your solution here \n", + " \n", + " ### END SOLUTION\n", + " \n", + " return m" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "_4pQ07e2R_Ub", + "colab_type": "code", + "outputId": "8ab72317-f57e-4ccc-a015-a21e8849af1c", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "print(\"Variance of Data:\", variance(data))" + ], + "execution_count": 94, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Variance of Data: 33.4302790000001\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LZcfSOEwrw2w", + "colab_type": "code", + "outputId": "27ffbe4a-2406-4ae3-f8f4-8d80a5017868", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "import numpy as np\n", + "print(np.var(data))" + ], + "execution_count": 93, + "outputs": [ + { + "output_type": "stream", + "text": [ + "33.43027899999999\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "n0yQdF-uR_Ue", + "colab_type": "text" + }, + "source": [ + "## Histogramming" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "2EI_oj_ER_Uf", + "colab_type": "text" + }, + "source": [ + "*Exercise 3:* Write a function that bins the data so that you can create a histogram. An example of how to implement histogramming is the following logic:\n", + "\n", + "* User inputs a list of values `x` and optionally `n_bins` which defaults to 10.\n", + "* If not supplied, find the minimum and maximum (`x_min`,`x_max`) of the values in x.\n", + "* Determine the bin size (`bin_size`) by dividing the range of the function by the number of bins.\n", + "* Create an empty list of zeros of size `n_bins`, call it `hist`.\n", + "* Loop over the values in `x`\n", + " * Loop over the values in `hist` with index `i`:\n", + " * If x is between `x_min+i*bin_size` and `x_min+i*2*bin_size`, increment `hist[i].` \n", + " * For efficiency, try to use continue to goto the next bin and data point.\n", + "* Return `hist` and the list corresponding of the bin edges (i.e. of `x_min+i*bin_size`). " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xYXsJGGHR_Uf", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Solution\n", + "def arange(x_min, x_max, steps=10):\n", + " step_size=(x_max-x_min)/steps\n", + " x=x_min\n", + " out=[0]\n", + " for i in range(steps):\n", + " out.append(x)\n", + " x+=step_size\n", + " return out\n", + "\n", + "\n", + "def histogram(x,n_bins=10,x_min=None,x_max=None):\n", + " if x_min==None:\n", + " x_min=min(data)\n", + " if x_max==None:\n", + " x_max=max(data)\n", + " \n", + " bin_edges=arange(x_min,x_max, n_bins)\n", + " bin_edges.append(x_max)\n", + " \n", + " hist= [0] * n_bins\n", + "\n", + " for a in x:\n", + " for i in range(n_bins):\n", + " if a>=bin_edges[i] and a)" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 106 + }, + { + "output_type": "display_data", + "data": { + "image/png": "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\nGmdRS1Lj/h+ZxWXAZry7QAAAAABJRU5ErkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "tags": [] + } + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "vAy9bGmTR_Uk", + "colab_type": "text" + }, + "source": [ + "*Exercise 4:* Write a function that uses the histogram function in the previous exercise to create a text-based \"graph\". For example the output could look like the following:\n", + "```\n", + "[ 0, 1] : ######\n", + "[ 1, 2] : #####\n", + "[ 2, 3] : ######\n", + "[ 3, 4] : ####\n", + "[ 4, 5] : ####\n", + "[ 5, 6] : ######\n", + "[ 6, 7] : #####\n", + "[ 7, 8] : ######\n", + "[ 8, 9] : ####\n", + "[ 9, 10] : #####\n", + "```\n", + "\n", + "Where each line corresponds to a bin and the number of `#`'s are proportional to the value of the data in the bin. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "rA2tKsFaR_Ul", + "colab_type": "code", + "colab": {} + }, + "source": [ + "# Solution\n", + "def draw_histogram(x,n_bins,x_min=None,x_max=None,character=\"#\",max_character_per_line=20):\n", + " h, b=histogram(x,n_bins)\n", + "\n", + " for i in range(0,n_bins):\n", + " print(b[i]*character)\n", + "\n", + " \n", + " \n", + "\n", + " ### BEGIN SOLUTION\n", + "\n", + " # Fill in your solution here \n", + " \n", + " ### END SOLUTION \n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "B_yGbeijxmsh", + "colab_type": "code", + "colab": {} + }, + "source": [ + "draw_histogram(data,20)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "XoNy1WikR_Un", + "colab_type": "code", + "outputId": "30d3b335-d23c-4bc2-f19d-002249ce7832", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + } + }, + "source": [ + "# Test your solution here\n", + "h,b=histogram(data,20)\n", + "print(h)\n" + ], + "execution_count": 107, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[0, 52, 55, 61, 46, 49, 47, 51, 45, 49, 55, 45, 66, 47, 43, 58, 51, 44, 28, 51]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "wu0ihO4PR_Uq", + "colab_type": "text" + }, + "source": [ + "## Functional Programming\n", + "\n", + "*Exercise 5:* Write a function the applies a booling function (that returns true/false) to every element in data, and return a list of indices of elements where the result was true. Use this function to find the indices of entries greater than 0.5. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "mQ_IbqZQR_Uq", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def where(mylist,myfunc):\n", + " out= []\n", + "\n", + " for index, element in enumerate(mylist):\n", + " if myfunc(element):\n", + " out.append(index)\n", + " \n", + " ### BEGIN SOLUTION\n", + "\n", + " # Fill in your solution here \n", + " \n", + " ### END SOLUTION\n", + " \n", + " return out\n", + "\n", + "def greater_than_five(x):\n", + " return x>5" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "aDAf3yEkU_a2", + "colab_type": "code", + "colab": {} + }, + "source": [ + " def greater_five(x):\n", + " out=[]\n", + "\n", + " for index, element in enumerate(x):\n", + " if element>5:\n", + " out.append(index)\n", + "\n", + " return out" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "yKjh5hL9VQ_2", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "d478ddbf-b65b-493d-be8d-e69897078d02" + }, + "source": [ + "greater_five(data)" + ], + "execution_count": 45, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[0,\n", + " 1,\n", + " 3,\n", + " 6,\n", + " 10,\n", + " 21,\n", + " 23,\n", + " 35,\n", + " 38,\n", + " 40,\n", + " 53,\n", + " 54,\n", + " 67,\n", + " 82,\n", + " 83,\n", + " 89,\n", + " 96,\n", + " 102,\n", + " 112,\n", + " 116,\n", + " 122,\n", + " 126,\n", + " 131,\n", + " 145,\n", + " 146,\n", + " 147,\n", + " 156,\n", + " 157,\n", + " 158,\n", + " 169,\n", + " 171,\n", + " 197,\n", + " 209,\n", + " 225,\n", + " 232,\n", + " 237,\n", + " 245,\n", + " 250,\n", + " 251,\n", + " 255,\n", + " 258,\n", + " 264,\n", + " 266,\n", + " 274,\n", + " 275,\n", + " 281,\n", + " 284,\n", + " 285,\n", + " 290,\n", + " 291,\n", + " 294,\n", + " 297,\n", + " 299,\n", + " 311,\n", + " 312,\n", + " 321,\n", + " 323,\n", + " 324,\n", + " 339,\n", + " 343,\n", + " 345,\n", + " 346,\n", + " 347,\n", + " 349,\n", + " 353,\n", + " 356,\n", + " 357,\n", + " 359,\n", + " 368,\n", + " 371,\n", + " 376,\n", + " 382,\n", + " 386,\n", + " 393,\n", + " 399,\n", + " 400,\n", + " 407,\n", + " 414,\n", + " 419,\n", + " 428,\n", + " 434,\n", + " 439,\n", + " 440,\n", + " 454,\n", + " 466,\n", + " 468,\n", + " 480,\n", + " 487,\n", + " 493,\n", + " 496,\n", + " 498,\n", + " 505,\n", + " 513,\n", + " 517,\n", + " 528,\n", + " 529,\n", + " 530,\n", + " 538,\n", + " 547,\n", + " 556,\n", + " 565,\n", + " 570,\n", + " 583,\n", + " 590,\n", + " 593,\n", + " 594,\n", + " 600,\n", + " 601,\n", + " 604,\n", + " 617,\n", + " 618,\n", + " 620,\n", + " 625,\n", + " 626,\n", + " 637,\n", + " 639,\n", + " 640,\n", + " 641,\n", + " 645,\n", + " 647,\n", + " 649,\n", + " 651,\n", + " 652,\n", + " 656,\n", + " 664,\n", + " 695,\n", + " 700,\n", + " 703,\n", + " 704,\n", + " 709,\n", + " 712,\n", + " 716,\n", + " 719,\n", + " 747,\n", + " 748,\n", + " 753,\n", + " 760,\n", + " 771,\n", + " 774,\n", + " 779,\n", + " 780,\n", + " 796,\n", + " 801,\n", + " 807,\n", + " 819,\n", + " 822,\n", + " 823,\n", + " 826,\n", + " 831,\n", + " 832,\n", + " 834,\n", + " 835,\n", + " 838,\n", + " 843,\n", + " 856,\n", + " 861,\n", + " 862,\n", + " 865,\n", + " 869,\n", + " 881,\n", + " 895,\n", + " 896,\n", + " 897,\n", + " 907,\n", + " 916,\n", + " 927,\n", + " 929,\n", + " 938,\n", + " 939,\n", + " 940,\n", + " 943,\n", + " 951,\n", + " 957,\n", + " 961,\n", + " 966,\n", + " 980,\n", + " 984,\n", + " 986,\n", + " 993,\n", + " 997]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 45 + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "UF0qIvNIR_Ut", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 1000 + }, + "outputId": "61da7731-30bc-49ed-ef6b-46488557af7f" + }, + "source": [ + "# Test your solution here\n", + "print(data)\n", + "where(data, greater_than_five)" + ], + "execution_count": 40, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[0,\n", + " 1,\n", + " 3,\n", + " 6,\n", + " 10,\n", + " 21,\n", + " 23,\n", + " 35,\n", + " 38,\n", + " 40,\n", + " 53,\n", + " 54,\n", + " 67,\n", + " 82,\n", + " 83,\n", + " 89,\n", + " 96,\n", + " 102,\n", + " 112,\n", + " 116,\n", + " 122,\n", + " 126,\n", + " 131,\n", + " 145,\n", + " 146,\n", + " 147,\n", + " 156,\n", + " 157,\n", + " 158,\n", + " 169,\n", + " 171,\n", + " 197,\n", + " 209,\n", + " 225,\n", + " 232,\n", + " 237,\n", + " 245,\n", + " 250,\n", + " 251,\n", + " 255,\n", + " 258,\n", + " 264,\n", + " 266,\n", + " 274,\n", + " 275,\n", + " 281,\n", + " 284,\n", + " 285,\n", + " 290,\n", + " 291,\n", + " 294,\n", + " 297,\n", + " 299,\n", + " 311,\n", + " 312,\n", + " 321,\n", + " 323,\n", + " 324,\n", + " 339,\n", + " 343,\n", + " 345,\n", + " 346,\n", + " 347,\n", + " 349,\n", + " 353,\n", + " 356,\n", + " 357,\n", + " 359,\n", + " 368,\n", + " 371,\n", + " 376,\n", + " 382,\n", + " 386,\n", + " 393,\n", + " 399,\n", + " 400,\n", + " 407,\n", + " 414,\n", + " 419,\n", + " 428,\n", + " 434,\n", + " 439,\n", + " 440,\n", + " 454,\n", + " 466,\n", + " 468,\n", + " 480,\n", + " 487,\n", + " 493,\n", + " 496,\n", + " 498,\n", + " 505,\n", + " 513,\n", + " 517,\n", + " 528,\n", + " 529,\n", + " 530,\n", + " 538,\n", + " 547,\n", + " 556,\n", + " 565,\n", + " 570,\n", + " 583,\n", + " 590,\n", + " 593,\n", + " 594,\n", + " 600,\n", + " 601,\n", + " 604,\n", + " 617,\n", + " 618,\n", + " 620,\n", + " 625,\n", + " 626,\n", + " 637,\n", + " 639,\n", + " 640,\n", + " 641,\n", + " 645,\n", + " 647,\n", + " 649,\n", + " 651,\n", + " 652,\n", + " 656,\n", + " 664,\n", + " 695,\n", + " 700,\n", + " 703,\n", + " 704,\n", + " 709,\n", + " 712,\n", + " 716,\n", + " 719,\n", + " 747,\n", + " 748,\n", + " 753,\n", + " 760,\n", + " 771,\n", + " 774,\n", + " 779,\n", + " 780,\n", + " 796,\n", + " 801,\n", + " 807,\n", + " 819,\n", + " 822,\n", + " 823,\n", + " 826,\n", + " 831,\n", + " 832,\n", + " 834,\n", + " 835,\n", + " 838,\n", + " 843,\n", + " 856,\n", + " 861,\n", + " 862,\n", + " 865,\n", + " 869,\n", + " 881,\n", + " 895,\n", + " 896,\n", + " 897,\n", + " 907,\n", + " 916,\n", + " 927,\n", + " 929,\n", + " 938,\n", + " 939,\n", + " 940,\n", + " 943,\n", + " 951,\n", + " 957,\n", + " 961,\n", + " 966,\n", + " 980,\n", + " 984,\n", + " 986,\n", + " 993,\n", + " 997]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 40 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "kuEPYBkGR_Uw", + "colab_type": "text" + }, + "source": [ + "*Exercise 6:* The inrange(mymin,mymax) function below returns a function that tests if it's input is between the specified values. Write corresponding functions that test:\n", + "* Even\n", + "* Odd\n", + "* Greater than\n", + "* Less than\n", + "* Equal\n", + "* Divisible by" + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AmP9x8O7R_Uw", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + }, + "outputId": "4731f7a0-be9e-47df-9933-ddb532b24d5b" + }, + "source": [ + "def in_range(mymin,mymax):\n", + " def between(x):\n", + " return x=mymin\n", + " return between\n", + "\n", + "# Examples:\n", + "F1=in_range(0,10)\n", + "F2=in_range(10,20)\n", + "\n", + "# Test of in_range\n", + "print(F1(0), F1(1), F1(10), F1(15), F1(20))\n", + "print(F2(0), F2(1), F2(10), F2(15), F2(20))\n", + "\n", + "print(\"Number of Entries passing F1:\", len(where(data,F1)))\n", + "print(\"Number of Entries passing F2:\", len(where(data,F2)))" + ], + "execution_count": 46, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True True False False False\n", + "False False True True False\n", + "Number of Entries passing F1: 490\n", + "Number of Entries passing F2: 0\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Diz9mY84R_Uz", + "colab_type": "code", + "colab": {} + }, + "source": [ + "### BEGIN SOLUTION\n", + "def is_even(x):\n", + " return x%2==0\n", + "\n", + "def is_odd(x):\n", + " return x%2!=0\n", + "\n", + "def is_greater_than(a):\n", + " def datas(x):\n", + " return x>a\n", + " return datas\n", + "\n", + "\n", + "def is_less_than(a):\n", + " def datas(x):\n", + " return x5, data)))\n", + "print(\"# of entries that are less than 5:\", sum(map(lambda x: x<5, data)))\n", + "print(\"# of entries that are equal to 5:\", sum(map(lambda x: x==5, data)))\n", + "print(\"# of entries that are divisible by 3:\", sum(map(lambda x: x%3==0, data)))" + ], + "execution_count": 79, + "outputs": [ + { + "output_type": "stream", + "text": [ + "# of entries that are even: 507\n", + "# of entries that are odd: 493\n", + "# of entries that are greater than 5: 180\n", + "# of entries that are less than 5: 769\n", + "# of entries that are equal to 5: 51\n", + "# of entries that are divisible by 3: 338\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "PglELr9_R_U7", + "colab_type": "text" + }, + "source": [ + "## Monte Carlo\n", + "\n", + "*Exercise 7:* Write a \"generator\" function called `generate_function(func,x_min,x_max,N)`, that instead of generating a flat distribution, generates a distribution with functional form coded in `func`. Note that `func` will always be > 0. \n", + "\n", + "Use the test function below and your histogramming functions above to demonstrate that your generator is working properly.\n", + "\n", + "Hint: A simple, but slow, solution is to a draw random number test_x within the specified range and another number p between the min and max of the function (which you will have to determine). If p<=function(test_x), then place test_x on the output. If not, repeat the process, drawing two new numbers. Repeat until you have the specified number of generated numbers, N. For this problem, it's OK to determine the min and max by numerically sampling the function. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "xjcJ4i3qR_U7", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def generate_function(func,x_min,x_max,N=1000):\n", + " out = list()\n", + "\n", + " x_scan=arange(x_min, x_max, 100)\n", + " y_scan=list(map(func, x_scan))\n", + " y_min=min(y_scan)\n", + " y_max=max(y_scan)\n", + "\n", + " while len(out))" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 83 + }, + { + "output_type": "display_data", + "data": { + "image/png": "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\nrkJggg==\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "tags": [] + } + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "VZzVx1i_R_U_", + "colab_type": "text" + }, + "source": [ + "*Exercise 8:* Use your function to generate 1000 numbers that are normal distributed, using the `gaussian` function below. Confirm the mean and variance of the data is close to the mean and variance you specify when building the Gaussian. Histogram the data. " + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "AhSTTxTcR_U_", + "colab_type": "code", + "colab": {} + }, + "source": [ + "import math\n", + "\n", + "def gaussian(mean, sigma):\n", + " def f(x):\n", + " return math.exp(-((x-mean)**2)/(2*sigma**2))/math.sqrt(math.pi*sigma)\n", + " return f\n", + "\n", + "# Example Instantiation\n", + "g1=gaussian(0,1)\n", + "g2=gaussian(10,3)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "W-NKDlXklxzt", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 351 + }, + "outputId": "0725df0e-a1d1-484d-919a-f8b578163db6" + }, + "source": [ + "g1info=generate_function(g1,0,10,1000)\n", + "plt.hist(g1info)" + ], + "execution_count": 86, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(array([242., 234., 194., 137., 84., 51., 34., 14., 6., 4.]),\n", + " array([3.11044595e-03, 3.23691713e-01, 6.44272980e-01, 9.64854247e-01,\n", + " 1.28543551e+00, 1.60601678e+00, 1.92659805e+00, 2.24717931e+00,\n", + " 2.56776058e+00, 2.88834185e+00, 3.20892312e+00]),\n", + " )" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 86 + }, + { + "output_type": "display_data", + "data": { + "image/png": "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\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "tags": [] + } + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "BzI-XSkkmBLH", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 350 + }, + "outputId": "9c0576ec-2195-40b3-e5ed-6f230cab6229" + }, + "source": [ + "g2info=generate_function(g2,5,15,1000)\n", + "plt.hist(g2info)" + ], + "execution_count": 89, + "outputs": [ + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "(array([ 59., 79., 101., 114., 140., 143., 146., 103., 68., 47.]),\n", + " array([ 5.09776993, 6.08298058, 7.06819123, 8.05340188, 9.03861253,\n", + " 10.02382317, 11.00903382, 11.99424447, 12.97945512, 13.96466577,\n", + " 14.94987642]),\n", + " )" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 89 + }, + { + "output_type": "display_data", + "data": { + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAADh0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uMy4yLjEsIGh0\ndHA6Ly9tYXRwbG90bGliLm9yZy+j8jraAAAPBklEQVR4nO3dbYwdV33H8e+vcXlI2uIEL66xA2uB\nFZRGUKJVGoqEEKHUEITzAqFEtBiwZFVNgQJScEAir6iMQE2D2lK5JMRIUSByQbHKQ7FcUFSJuN0E\nyJOBWCEPdu14ESR9QCp1+++LHaRbe53dvXPv3vj4+5GsO3POzJ3/yPZvz547MzdVhSSpLb8y6QIk\nSaNnuEtSgwx3SWqQ4S5JDTLcJalBqyZdAMCaNWtqenp60mVI0hnlnnvu+UlVTS3U96wI9+npaWZn\nZyddhiSdUZI8dro+p2UkqUGGuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSgwx3SWqQ4S5JDTLcJalBz4o7\nVCWdanrHVydy3Ed3XjmR42q0HLlLUoMMd0lqkOEuSQ1yzl1axKTmvqU+Fh25J7klyfEkDyzQ9+Ek\nlWRNt54kn0lyKMl9SS4dR9GSpGe2lGmZW4HNJzcmuRB4E/D4QPObgU3dn+3AZ/uXKElarkXDvaru\nAn66QNeNwHVADbRtAb5Q8+4GVidZN5JKJUlLNtSce5ItwJGq+n6Swa71wBMD64e7tqMLvMd25kf3\nvOQlLxmmDJ1FnPeWlmfZV8skORf4KPDxPgeuql1VNVNVM1NTC34FoCRpSMOM3F8GbAR+OWrfANyb\n5DLgCHDhwLYbujZJ0gpa9si9qu6vqhdV1XRVTTM/9XJpVR0D9gLv6q6auRx4uqpOmZKRJI3XUi6F\nvB34DnBRksNJtj3D5l8DHgEOAX8L/PFIqpQkLcui0zJVdc0i/dMDywVc278sSVIfPn5AkhpkuEtS\ngwx3SWqQ4S5JDTLcJalBhrskNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXI\ncJekBhnuktQgw12SGmS4S1KDDHdJatBSviD7liTHkzww0PapJD9Icl+SryRZPdB3fZJDSX6Y5PfH\nVbgk6fSWMnK/Fdh8Uts+4JKqeiXwI+B6gCQXA1cDv9Xt89dJzhlZtZKkJVk03KvqLuCnJ7V9s6pO\ndKt3Axu65S3AF6vqv6rqx8Ah4LIR1itJWoJRzLm/F/h6t7weeGKg73DXJklaQb3CPcnHgBPAbUPs\nuz3JbJLZubm5PmVIkk4ydLgneTfwVuCdVVVd8xHgwoHNNnRtp6iqXVU1U1UzU1NTw5YhSVrAUOGe\nZDNwHfC2qvr5QNde4Ookz02yEdgE/HP/MiVJy7FqsQ2S3A68HliT5DBwA/NXxzwX2JcE4O6q+qOq\nejDJHcBDzE/XXFtV/zOu4iVJC1s03KvqmgWab36G7T8BfKJPUZKkfrxDVZIaZLhLUoMMd0lq0KJz\n7tKg6R1fnXQJkpbAkbskNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJek\nBhnuktQgw12SGmS4S1KDDHdJapDhLkkN8nnukv6fST6z/9GdV07s2K1ZdOSe5JYkx5M8MNB2QZJ9\nSR7uXs/v2pPkM0kOJbkvyaXjLF6StLClTMvcCmw+qW0HsL+qNgH7u3WANwObuj/bgc+OpkxJ0nIs\nOi1TVXclmT6peQvw+m55N/Bt4CNd+xeqqoC7k6xOsq6qjo6qYPlVd5IWN+wHqmsHAvsYsLZbXg88\nMbDd4a7tFEm2J5lNMjs3NzdkGZKkhfS+WqYbpdcQ++2qqpmqmpmamupbhiRpwLDh/mSSdQDd6/Gu\n/Qhw4cB2G7o2SdIKGjbc9wJbu+WtwJ0D7e/qrpq5HHja+XZJWnmLfqCa5HbmPzxdk+QwcAOwE7gj\nyTbgMeAd3eZfA94CHAJ+DrxnDDVLkhaxlKtlrjlN1xULbFvAtX2LkiT14+MHJKlBhrskNchwl6QG\nGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBhnuktQgw12SGmS4S1KDDHdJapDh\nLkkNMtwlqUGGuyQ1yHCXpAb1CvckH0zyYJIHktye5HlJNiY5kORQki8lec6oipUkLc3Q4Z5kPfB+\nYKaqLgHOAa4GPgncWFUvB34GbBtFoZKkpes7LbMKeH6SVcC5wFHgDcCern83cFXPY0iSlmnocK+q\nI8CngceZD/WngXuAp6rqRLfZYWD9Qvsn2Z5kNsns3NzcsGVIkhbQZ1rmfGALsBF4MXAesHmp+1fV\nrqqaqaqZqampYcuQJC1gVY993wj8uKrmAJJ8GXgtsDrJqm70vgE40r/MZ6fpHV+ddAmStKA+c+6P\nA5cnOTdJgCuAh4BvAW/vttkK3NmvREnScvWZcz/A/Aen9wL3d++1C/gI8KEkh4AXAjePoE5J0jL0\nmZahqm4Abjip+RHgsj7vK0nqxztUJalBhrskNchwl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y\n3CWpQYa7JDXIcJekBvV6towkjdKkHqP96M4rJ3LccXLkLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUIMNd\nkhpkuEtSgwx3SWpQr3BPsjrJniQ/SHIwyWuSXJBkX5KHu9fzR1WsJGlp+o7cbwK+UVWvAF4FHAR2\nAPurahOwv1uXJK2gocM9yQuA1wE3A1TVL6rqKWALsLvbbDdwVd8iJUnL02fkvhGYAz6f5LtJPpfk\nPGBtVR3ttjkGrF1o5yTbk8wmmZ2bm+tRhiTpZH0eHLYKuBR4X1UdSHITJ03BVFUlqYV2rqpdwC6A\nmZmZBbdZikk9aEiSns36jNwPA4er6kC3vof5sH8yyTqA7vV4vxIlScs1dLhX1THgiSQXdU1XAA8B\ne4GtXdtW4M5eFUqSlq3v89zfB9yW5DnAI8B7mP+BcUeSbcBjwDt6HkOStEy9wr2qvgfMLNB1RZ/3\nlST14x2qktQgw12SGmS4S1KDDHdJapDhLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSgwx3\nSWpQ36dCStIZb5Jf+vPozivH8r6O3CWpQYa7JDXIcJekBhnuktQgw12SGmS4S1KDeod7knOSfDfJ\n33frG5McSHIoyZe6L8+WJK2gUYzcPwAcHFj/JHBjVb0c+BmwbQTHkCQtQ69wT7IBuBL4XLce4A3A\nnm6T3cBVfY4hSVq+viP3vwCuA/63W38h8FRVnejWDwPrF9oxyfYks0lm5+bmepYhSRo0dLgneStw\nvKruGWb/qtpVVTNVNTM1NTVsGZKkBfR5tsxrgbcleQvwPOA3gJuA1UlWdaP3DcCR/mVKkpZj6JF7\nVV1fVRuqahq4GvjHqnon8C3g7d1mW4E7e1cpSVqWcVzn/hHgQ0kOMT8Hf/MYjiFJegYjeeRvVX0b\n+Ha3/Ahw2SjeV5I0HO9QlaQGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBhnu\nktQgw12SGmS4S1KDDHdJapDhLkkNMtwlqUGGuyQ1yHCXpAYZ7pLUIMNdkho0dLgnuTDJt5I8lOTB\nJB/o2i9Isi/Jw93r+aMrV5K0FH1G7ieAD1fVxcDlwLVJLgZ2APurahOwv1uXJK2gocO9qo5W1b3d\n8r8DB4H1wBZgd7fZbuCqvkVKkpZnJHPuSaaBVwMHgLVVdbTrOgasPc0+25PMJpmdm5sbRRmSpE7v\ncE/ya8DfAX9aVf822FdVBdRC+1XVrqqaqaqZqampvmVIkgb0Cvckv8p8sN9WVV/ump9Msq7rXwcc\n71eiJGm5+lwtE+Bm4GBV/flA115ga7e8Fbhz+PIkScNY1WPf1wJ/CNyf5Htd20eBncAdSbYBjwHv\n6FeiJGm5hg73qvonIKfpvmLY95Uk9ecdqpLUIMNdkhpkuEtSgwx3SWqQ4S5JDTLcJalBhrskNchw\nl6QGGe6S1CDDXZIaZLhLUoMMd0lqkOEuSQ0y3CWpQYa7JDXIcJekBhnuktQgw12SGmS4S1KDDHdJ\natDYwj3J5iQ/THIoyY5xHUeSdKqxhHuSc4C/At4MXAxck+TicRxLknSqcY3cLwMOVdUjVfUL4IvA\nljEdS5J0klVjet/1wBMD64eB3xncIMl2YHu3+h9JfjimWkZtDfCTSRcxAZ732eVsPO+JnHM+2Wv3\nl56uY1zhvqiq2gXsmtTxh5VktqpmJl3HSvO8zy5n43m3ds7jmpY5Alw4sL6ha5MkrYBxhfu/AJuS\nbEzyHOBqYO+YjiVJOslYpmWq6kSSPwH+ATgHuKWqHhzHsSbgjJtKGhHP++xyNp53U+ecqpp0DZKk\nEfMOVUlqkOEuSQ0y3Jchyeoke5L8IMnBJK+ZdE0rIckHkzyY5IEktyd53qRrGocktyQ5nuSBgbYL\nkuxL8nD3ev4kaxy105zzp7p/4/cl+UqS1ZOscRwWOu+Bvg8nqSRrJlHbqBjuy3MT8I2qegXwKuDg\nhOsZuyTrgfcDM1V1CfMfkF892arG5lZg80ltO4D9VbUJ2N+tt+RWTj3nfcAlVfVK4EfA9Std1Aq4\nlVPPmyQXAm8CHl/pgkbNcF+iJC8AXgfcDFBVv6iqpyZb1YpZBTw/ySrgXOBfJ1zPWFTVXcBPT2re\nAuzulncDV61oUWO20DlX1Ter6kS3ejfz96k05TR/1wA3AtcBZ/yVJob70m0E5oDPJ/luks8lOW/S\nRY1bVR0BPs38SOYo8HRVfXOyVa2otVV1tFs+BqydZDET8F7g65MuYiUk2QIcqarvT7qWUTDcl24V\ncCnw2ap6NfCftPcr+im6OeYtzP9wezFwXpI/mGxVk1Hz1w2f8SO6pUryMeAEcNukaxm3JOcCHwU+\nPulaRsVwX7rDwOGqOtCt72E+7Fv3RuDHVTVXVf8NfBn43QnXtJKeTLIOoHs9PuF6VkSSdwNvBd5Z\nZ8fNMC9jfgDz/SSPMj8VdW+S35xoVT0Y7ktUVceAJ5Jc1DVdATw0wZJWyuPA5UnOTRLmz7v5D5IH\n7AW2dstbgTsnWMuKSLKZ+Xnnt1XVzyddz0qoqvur6kVVNV1V08wP5i7t/t+fkQz35XkfcFuS+4Df\nBv5swvWMXfebyh7gXuB+5v/NNHWb9i8luR34DnBRksNJtgE7gd9L8jDzv8XsnGSNo3aac/5L4NeB\nfUm+l+RvJlrkGJzmvJvi4wckqUGO3CWpQYa7JDXIcJekBhnuktQgw12SGmS4S1KDDHdJatD/AYSn\njv64bfqgAAAAAElFTkSuQmCC\n", + "text/plain": [ + "
" + ] + }, + "metadata": { + "tags": [] + } + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "HXCbkQiImYvc", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + }, + "outputId": "57fb51a1-87da-47a5-c1b0-03f4e16e25ca" + }, + "source": [ + "print(mean(g1info), variance(g1info))\n", + "print(mean(g2info), variance(g2info))" + ], + "execution_count": 97, + "outputs": [ + { + "output_type": "stream", + "text": [ + "0.8018799043020864 0.3600985339731254\n", + "9.993224116867157 5.699140138239852\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "09uXtZ_7R_VB", + "colab_type": "text" + }, + "source": [ + "*Exercise 9:* Combine your `generate_function`, `where`, and `in_range` functions above to create an integrate function. Use your integrate function to show that approximately 68% of Normal distribution is within one variance." + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "QPjfq47KR_VC", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def integrate(func, x_min, x_max, n_points=1000):\n", + " out = list()\n", + " x_scan = arange(x_min,x_max,100)\n", + " y_scan = list(map(func,x_scan))\n", + " y_min = min(y_scan)\n", + " y_max = max(y_scan)\n", + "\n", + " count=0\n", + " while len(out)self.__p1.getY()): \n", + " if (self.__p1.getY()+(increment*(itr)) <= self.__p2.getY()):\n", + " ptList.append((self.__p1.getX(),self.__p1.getY()+(increment*(itr)) ) )\n", + " else:\n", + " if (self.__p1.getY()-(increment*(itr)) >= self.__p2.getY()):\n", + " ptList.append((self.__p1.getX(),self.__p1.getY()-(increment*(itr)) ) )\n", + " \n", + " elif (self.__p1.getY()==self.__p2.getY()):\n", + " #horizontal line\n", + " if (self.__p2.getX()>self.__p1.getX()): \n", + " if (self.__p1.getX()+(increment*(itr)) <= self.__p2.getX()):\n", + " ptList.append((self.__p1.getX()+(increment*(itr)),self.__p1.getY() ) )\n", + " else:\n", + " if (self.__p1.getX()-(increment*(itr)) >= self.__p2.getX()):\n", + " ptList.append((self.__p1.getX()-(increment*(itr)),self.__p1.getY() ) )\n", + " else:\n", + " b = -1* (self.slope()*self.__p1.getX())+self.__p1.getY()\n", + " nexty = (self.slope()*(self.__p1.getX()+(increment*(itr))))+b\n", + " ptList.append(((self.__p1.getX()+(increment*(itr))), nexty))\n", + " \n", + " return ptList\n", + "\n", + " def slope(self):\n", + " if (self.__x2!=self.__x1):\n", + " return (self.__y2-self.__y1)/(self.__x2-self.__x1)\n", + " else:\n", + " return None\n", + "\n", + " " + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "GnNbxBDyTj0N", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + }, + "outputId": "5e032c37-c71d-40d5-c6db-4a9880ce28c3" + }, + "source": [ + "p1=point(2,3)\n", + "print(p1)\n", + "print(p1.getX())\n", + "line1=line(3,1,3,9)\n", + "print(line1.endpoint(1))\n", + "print(line1.endpoint(2))\n", + "print(line1.length())\n", + "print(line1.slope())" + ], + "execution_count": 104, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(2,3)\n", + "2\n", + "(3,1)\n", + "(3,9)\n", + "8.0\n", + "None\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "j9s8O81Mffqc", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class shape():\n", + " def __init__(self, x1, y1, x2, y2):\n", + " self._line1=line(x1, y1, x2, y2)\n", + "\n", + " def area(self):\n", + " pass\n", + " \n", + " def perimeter(self):\n", + " pass\n", + " \n", + " def isWithin(self, compareX, compareY):\n", + " #find if a point is inside the perimeter of a shape\n", + " pass\n", + " \n", + " def borderList(self, maxPoints=16):\n", + " #return list of coords on perimeter of shape\n", + " pass\n", + "\n", + " def isOverlapping(self, coordList):\n", + " #return true or false if coordList passed has any points that overlap the shape\n", + " for testCoord in (coordList):\n", + " if (self.isWithin(testCoord[0], testCoord[1])):\n", + " return True\n", + " else:\n", + " pass\n", + " return False" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "CnHnppLrXjfW", + "colab_type": "code", + "colab": {} + }, + "source": [ + "#initial point is the top left corner\n", + "class rectangle(shape):\n", + " def __init__(self, x, y, width, length):\n", + " self.__width=width\n", + " self.__length=length\n", + " shape.__init__(self, x, y, x+length, y)\n", + " self.__line2 = line(x+length,y, x+length,y-width)\n", + " self.__line3 = line(x+length,y-width, x,y-width)\n", + " self.__line4 = line(x,y-width, x,y)\n", + "\n", + " def width(self):\n", + " return self.__width\n", + " def length(self):\n", + " return self.__length\n", + "\n", + " def area(self):\n", + " return self.__width*self.__length\n", + "\n", + " def perimeter(self):\n", + " return 2*(self.__width+self.__length)\n", + "\n", + " def isWithin(self, comX, comY):\n", + " #find if point is in rectangle perimeter\n", + " return(self.__line4.endpoint(1).getX() <= comX <= self._line1.endpoint(2).getX() and\n", + " self.__line4.endpoint(1).getY() <= comY <= self._line1.endpoint(2).getY())\n", + " \n", + " def borderList(self, maxPoints=16):\n", + " pointList= list()\n", + " stagger=(self.perimeter()/maxPoints)\n", + "\n", + " pointList.extend(self._line1.getPointsList(stagger))\n", + " pointList.extend(self.__line2.getPointsList(stagger))\n", + " pointList.extend(self.__line3.getPointsList(stagger))\n", + " pointList.extend(self.__line4.getPointsList(stagger))\n", + " \n", + " return pointList\n", + "\n", + "class circle(shape):\n", + " #radius is treated as line\n", + " def __init__(self, x, y, radius):\n", + " shape.__init__(self, x, y, x+radius, y)\n", + " self.__radius=radius\n", + "\n", + " def radius(self):\n", + " return self.__radius\n", + "\n", + " def area(self):\n", + " return math.pi*(self.__radius**2)\n", + "\n", + " def perimeter(self):\n", + " return 2*(math.pi)*self.__radius\n", + "\n", + " def isWithin(self, x,y):\n", + " return (x - (self._line1.endpoint(1).getX()))**2 + (y - (self._line1.endpoint(1).getY()))**2 <= self.__radius**2\n", + "\n", + "\n", + "\n", + "class triangle(shape):\n", + " #initial point is the top apex\n", + " def __init__(self, x, y, base, height):\n", + " shape.__init__(self, x, y, x, y-height)\n", + " self.__base=base\n", + " self.__height=height\n", + " self.__hypotenuse=math.sqrt(base**2+height**2)\n", + " self.__line2=line(x, y-height, x-base, y-height)\n", + " self.__line3=line(x-base, y-height, x, y)\n", + "\n", + " def base(self):\n", + " return self.__base\n", + " def height(self):\n", + " return self.__height\n", + " def hypotenuse(self):\n", + " return round(self.__hypotenuse, 2)\n", + "\n", + " def area(self):\n", + " return 0.5*(self.__base)*(self.__height)\n", + " \n", + " def perimeter(self):\n", + " return self.__base+self.__height+self.__hypotenuse\n", + "\n", + " def borderList(self, maxPoints=16):\n", + " pointList=list()\n", + " stagger=(self.perimeter()/maxPoints)\n", + "\n", + " pointList.extend(self._line1.getPointsList(stagger))\n", + " pointList.extend(self.__line2.getPointsList(stagger))\n", + " pointList.extend(self.__line3.getPointsList(stagger))\n", + " \n", + " return pointList\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "5NFVK3yCnfgj", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 105 + }, + "outputId": "00170c35-4273-4c3f-f39f-0a61294312e8" + }, + "source": [ + "rec=rectangle(5,5,3,4)\n", + "print(rec.isWithin(5,4))\n", + "print(rec.isWithin(1,1))\n", + "print(rec.perimeter())\n", + "print(rec.borderList())\n" + ], + "execution_count": 115, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "14\n", + "[(5.0, 5), (5.875, 5), (6.75, 5), (7.625, 5), (8.5, 5), (9, 5.0), (9, 4.125), (9, 3.25), (9, 2.375), (9.0, 2), (8.125, 2), (7.25, 2), (6.375, 2), (5.5, 2), (5, 2.0), (5, 2.875), (5, 3.75), (5, 4.625)]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "r0wXqUv8kzko", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 68 + }, + "outputId": "d783ff0b-cbb1-4597-9ab1-11696686541f" + }, + "source": [ + "cir=circle(0,0,3)\n", + "print(cir.isWithin(0,3))\n", + "print(cir.isWithin(-3,0))\n", + "print(cir.isWithin(0,3.01))" + ], + "execution_count": 108, + "outputs": [ + { + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "False\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "eXcl31InqaDv", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 54 + }, + "outputId": "298c9518-0443-4f46-8443-3692d0891f52" + }, + "source": [ + "tri=triangle(10,10,7,4)\n", + "print(tri.borderList())" + ], + "execution_count": 116, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[(10, 10.0), (10, 8.80860889073134), (10, 7.617217781462681), (10, 6.425826672194022), (10.0, 6), (8.80860889073134, 6), (7.617217781462681, 6), (6.425826672194022, 6), (5.234435562925363, 6), (4.043044453656703, 6), (3.0, 6.0), (4.191391109268659, 6.680794919582091), (5.382782218537319, 7.361589839164182), (6.574173327805978, 8.042384758746273), (7.765564437074637, 8.723179678328364), (8.956955546343297, 9.403974597910455), (10.148346655611956, 10.084769517492546)]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5O5TzpbiqEJ7", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 102 + }, + "outputId": "a517bf43-f824-44f9-e83b-7452bb4c1f31" + }, + "source": [ + "tri1=triangle(10,8,4,4)\n", + "tri2=triangle(-7,-2,3,2)\n", + "\n", + "rec1=rectangle(6,11,6,8)\n", + "rec2=rectangle(4,-4,6,2)\n", + "\n", + "print(\"rec 1 vs tri 1:\", rec1.isOverlapping(tri1.borderList()))\n", + "print(\"rec 1 vs tri 2:\", rec1.isOverlapping(tri2.borderList()))\n", + "print(\"rec 2 vs tri 1:\", rec2.isOverlapping(tri1.borderList()))\n", + "print(\"rec 1 vs rec 1:\", rec1.isOverlapping(rec2.borderList()))\n", + "print(\"tri 1 vs tri 2:\", tri1.isOverlapping(tri2.borderList()))" + ], + "execution_count": 118, + "outputs": [ + { + "output_type": "stream", + "text": [ + "rec 1 vs tri 1: True\n", + "rec 1 vs tri 2: False\n", + "rec 2 vs tri 1: False\n", + "rec 1 vs rec 1: False\n", + "tri 1 vs tri 2: False\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "Uzy_TqGYvQtg", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-6/Lab_6_Solutions.ipynb b/Labs/Lab-6/Lab_6_Solutions.ipynb new file mode 100644 index 0000000..9fb39e8 --- /dev/null +++ b/Labs/Lab-6/Lab_6_Solutions.ipynb @@ -0,0 +1,1541 @@ +{ + "nbformat": 4, + "nbformat_minor": 0, + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.8.1" + }, + "colab": { + "name": "Copy of Lab-6.ipynb", + "provenance": [] + } + }, + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "id": "9wgeYHU0dhn5", + "colab_type": "text" + }, + "source": [ + "# Lab 6\n" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "d8tXN6zSdhn5", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "N2UH3lxsilOH", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class Matrix:\n", + " __data=list()\n", + "\n", + " def __init__(self, m, n, fillVal=0):\n", + " if (isinstance(fillVal, list)):\n", + " check = True\n", + " if (len(fillVal)==m):\n", + " for element in (fillVal):\n", + " if (len(element)!=n):\n", + " isGood = False\n", + " break\n", + "\n", + " if (check):\n", + " self.__data = []\n", + " for element in (fillVal):\n", + " self.__data.append(element)\n", + " else:\n", + " if (n>=0 and m>=0):\n", + " self.__data = [[fillVal]*n for iter in range(m)]\n", + " \n", + " \n", + " def shape(self):\n", + " return((len(self.__data), len(self.__data[0])))\n", + " \n", + " def areCompatable(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " rows, cols = testM.shape()\n", + " myRows, myCols = self.shape()\n", + " if (myRows == rows and myCols == cols ):\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + "\n", + " def areEqual(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " if (self.areCompatable(testM)):\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " if (self.__data[i][j] != testM[i][j]):\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " \n", + " return True\n", + "\n", + " def __str__(self):\n", + " return '\\n'.join(map(str, self.__data)) \n", + " \n", + " def __getitem__(self, index):\n", + " if (isinstance(index,int)):\n", + " return self.__data[index]\n", + " elif (isinstance(index,tuple)):\n", + " row, col = index\n", + " return self.__data[row][col]\n", + " else:\n", + " return None \n", + "\n", + " \n", + " def __eq__(self, compare):\n", + " return self.areEqual(compare)\n", + " \n", + " def __ne__(self, compare):\n", + " if (self.areEqual(compare) == True):\n", + " return False\n", + " else:\n", + " return True" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "Pq9WLPsYEoxG", + "colab_type": "code", + "outputId": "93c98fda-b43c-4851-e146-d862ba75ba50", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "m1=Matrix(2,3)\n", + "print(m1.shape())\n", + "print(m1)\n", + "print(m1[0][0])" + ], + "execution_count": 113, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(2, 3)\n", + "[0, 0, 0]\n", + "[0, 0, 0]\n", + "0\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LfbXiI1bEozP", + "colab_type": "code", + "outputId": "602e559b-1e2e-458e-f133-882a43e394a1", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "m2=Matrix(4,4,10)\n", + "print(m2.shape())\n", + "print(m2)\n", + "print(m2[1][0])" + ], + "execution_count": 114, + "outputs": [ + { + "output_type": "stream", + "text": [ + "(4, 4)\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "10\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "5y1n4z0BFBK3", + "colab_type": "code", + "outputId": "3cbc7b08-c7ec-4230-b217-e9339958d0a9", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + } + }, + "source": [ + "m1[0][0]=5\n", + "print(m1)\n", + "\n", + "print('\\n')\n", + "m2[1][0]=2\n", + "print(m2)" + ], + "execution_count": 115, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[5, 0, 0]\n", + "[0, 0, 0]\n", + "\n", + "\n", + "[10, 10, 10, 10]\n", + "[2, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "3Gn_Yo-NFymF", + "colab_type": "code", + "outputId": "256c9f75-f8df-4f6b-88d5-812b0044d615", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 85 + } + }, + "source": [ + "print(m1.areCompatable(m2))\n", + "print(m1==m2)\n", + "\n", + "m3=Matrix(4,4,6)\n", + "print(m2.areCompatable(m3))\n", + "print(m2==m3)" + ], + "execution_count": 116, + "outputs": [ + { + "output_type": "stream", + "text": [ + "False\n", + "False\n", + "True\n", + "False\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "uucB2mOpdhn6", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "E7AjKFQLGdHB", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class Matrix:\n", + " __data=list()\n", + "\n", + " def __init__(self, m, n, fillVal=0):\n", + " if (isinstance(fillVal, list)):\n", + " check = True\n", + " if (len(fillVal)==m):\n", + " for element in (fillVal):\n", + " if (len(element)!=n):\n", + " isGood = False\n", + " break\n", + "\n", + " if (check):\n", + " self.__data = []\n", + " for element in (fillVal):\n", + " self.__data.append(element)\n", + " else:\n", + " if (n>=0 and m>=0):\n", + " self.__data = [[fillVal]*n for iter in range(m)]\n", + " \n", + " \n", + " def shape(self):\n", + " return((len(self.__data), len(self.__data[0])))\n", + " \n", + " def areCompatable(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " rows, cols = testM.shape()\n", + " myRows, myCols = self.shape()\n", + " if (myRows == rows and myCols == cols ):\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " \n", + " def areEqual(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " if (self.areCompatable(testM)):\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " if (self.__data[i][j] != testM[i][j]):\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " \n", + " return True\n", + "\n", + " def transpose(self):\n", + " rows=len(self.__data)\n", + " cols=len(self.__data[0])\n", + " out=list()\n", + " for i in range(rows):\n", + " row=list()\n", + " for j in range(cols):\n", + " row.append(self.__data[j][i])\n", + " out.append(row)\n", + " return out\n", + "\n", + " #for row(n) im assuming Dr.Farbin means take the nth row and convert it to a (length of row)x1 matrix\n", + " #ex: 3x3 matrix ==> nth row would be converted to a 3x1 matrix\n", + " def row(self, n):\n", + " out=list()\n", + " x=self.__data[n]\n", + "\n", + " for i in range(len(x)):\n", + " rows=list()\n", + " for j in range(0,1):\n", + " rows.append(x[i])\n", + " out.append(rows)\n", + " return out\n", + "\n", + " #for column(n) im assuming Dr.Farbin means take the nth col and convert it to 1x(# of rows in column) matrix\n", + " def column(self, n):\n", + " out=list()\n", + " \n", + " for i in range(len(self.__data)):\n", + " for j in range(len(self.__data[i])):\n", + " out.append(self.__data[i][n])\n", + " break\n", + " return out\n", + "\n", + " def to_list(self):\n", + " return list(self.__data)\n", + "\n", + " def block(self, m_0,m_1,n_0,n_1):\n", + " myRows, myCols = self.shape()\n", + " if((m_0>=0 and m_1 <= myRows-1) and (n_0>=0 and n_1<= myCols-1)):\n", + " out=list()\n", + " for x in self.__data[m_0:m_1]:\n", + " out.append(x[n_0:n_1+1])\n", + " return out\n", + " else:\n", + " return None\n", + "\n", + "\n", + " def __str__(self):\n", + " return '\\n'.join(map(str, self.__data)) \n", + " \n", + " def __getitem__(self, index):\n", + " if (isinstance(index,int)):\n", + " return self.__data[index]\n", + " elif (isinstance(index,tuple)):\n", + " row, col = index\n", + " return self.__data[row][col]\n", + " else:\n", + " return None \n", + "\n", + " \n", + " def __eq__(self, compare):\n", + " return self.areEqual(compare)\n", + " \n", + " def __ne__(self, compare):\n", + " if (self.areEqual(compare) == True):\n", + " return False\n", + " else:\n", + " return True" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "fZ_ZfQ9YHW3b", + "colab_type": "code", + "outputId": "0e42667a-254d-4cde-bc82-453d055cd0de", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 119 + } + }, + "source": [ + "data=[[1,2,3],[4,5,6],[7,8,9]]\n", + "m4=Matrix(3, 3, data)\n", + "print(m4)\n", + "print(\"Tranpose: \",m4.transpose())\n", + "print(\"Return 3x1 matrix of row 2:\",m4.row(1))\n", + "print(\"Return 1x3 matrix of column 1:\",m4.column(0))" + ], + "execution_count": 118, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[1, 2, 3]\n", + "[4, 5, 6]\n", + "[7, 8, 9]\n", + "Tranpose: [[1, 4, 7], [2, 5, 8], [3, 6, 9]]\n", + "Return 3x1 matrix of row 2: [[4], [5], [6]]\n", + "Return 1x3 matrix of column 1: [1, 4, 7]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "8MQ8QxSzNt1_", + "colab_type": "code", + "outputId": "e97df432-073b-4256-f172-37d5d85198bd", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 51 + } + }, + "source": [ + "print(m4.to_list())\n", + "m4.block(0,2,1,2)" + ], + "execution_count": 119, + "outputs": [ + { + "output_type": "stream", + "text": [ + "[[1, 2, 3], [4, 5, 6], [7, 8, 9]]\n" + ], + "name": "stdout" + }, + { + "output_type": "execute_result", + "data": { + "text/plain": [ + "[[2, 3], [5, 6]]" + ] + }, + "metadata": { + "tags": [] + }, + "execution_count": 119 + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "IzOzXnJAdhn7", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "alBvqi0MzJaR", + "colab_type": "code", + "colab": {} + }, + "source": [ + "def constant(n,m,c):\n", + " return [ [c for _ in range(m)] for _ in range(n)]\n", + "\n", + "def zeros(n,m):\n", + " return [ [0 for _ in range(m)] for _ in range(n)]\n", + "\n", + "def ones(n,m):\n", + " return [ [1 for _ in range(m)] for _ in range(n)]\n", + "\n", + "\n", + "def eye(n):\n", + " M=Matrix(n,n)\n", + " for i in range(n):\n", + " M[i][i]=1\n", + " return M\n" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3G9Vc60dzUhP", + "colab_type": "code", + "outputId": "8d571a8f-9352-4b26-9b3c-d9405eed7f05", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + } + }, + "source": [ + "print(\"Constant matrix:\",constant(2,2,4.5))\n", + "print(\"\\nZero matrix:\",zeros(3,3))\n", + "print(\"\\nOnes matrix:\",ones(2,3))\n", + "print(\"\\nIdentity matrix:\",eye(4))" + ], + "execution_count": 121, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Constant matrix: [[4.5, 4.5], [4.5, 4.5]]\n", + "\n", + "Zero matrix: [[0, 0, 0], [0, 0, 0], [0, 0, 0]]\n", + "\n", + "Ones matrix: [[1, 1, 1], [1, 1, 1]]\n", + "\n", + "Identity matrix: [1, 0, 0, 0]\n", + "[0, 1, 0, 0]\n", + "[0, 0, 1, 0]\n", + "[0, 0, 0, 1]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "mq-ygKz5dhn7", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "RSk4z9ckbiAM", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class Matrix:\n", + " __data=list()\n", + "\n", + " def __init__(self, m, n, fillVal=0):\n", + " if (isinstance(fillVal, list)):\n", + " check = True\n", + " if (len(fillVal)==m):\n", + " for element in (fillVal):\n", + " if (len(element)!=n):\n", + " isGood = False\n", + " break\n", + "\n", + " if (check):\n", + " self.__data = []\n", + " for element in (fillVal):\n", + " self.__data.append(element)\n", + " else:\n", + " if (n>=0 and m>=0):\n", + " self.__data = [[fillVal]*n for iter in range(m)]\n", + " \n", + " \n", + " def shape(self):\n", + " return((len(self.__data), len(self.__data[0])))\n", + " \n", + " def areCompatable(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " rows, cols = testM.shape()\n", + " myRows, myCols = self.shape()\n", + " if (myRows == rows and myCols == cols ):\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + "\n", + " def transpose(self):\n", + " rows=len(self.__data)\n", + " cols=len(self.__data[0])\n", + " out=list()\n", + " for i in range(rows):\n", + " row=list()\n", + " for j in range(cols):\n", + " row.append(self.__data[j][i])\n", + " out.append(row)\n", + " return out\n", + "\n", + " #for row(n) im assuming Dr.Farbin means take the nth row and convert it to a (length of row)x1 matrix\n", + " #ex: 3x3 matrix ==> nth row would be converted to a 3x1 matrix\n", + " def row(self, n):\n", + " out=list()\n", + " x=self.__data[n]\n", + "\n", + " for i in range(len(x)):\n", + " rows=list()\n", + " for j in range(0,1):\n", + " rows.append(x[i])\n", + " out.append(rows)\n", + " return out\n", + " \n", + " #for column(n) im assuming Dr.Farbin means take the nth col and convert it to 1x(# of rows in column) matrix\n", + " def column(self, n):\n", + " out=list()\n", + " \n", + " for i in range(len(self.__data)):\n", + " for j in range(len(self.__data[i])):\n", + " out.append(self.__data[i][n])\n", + " break\n", + " return out\n", + "\n", + " def to_list(self):\n", + " return list(self.__data)\n", + "\n", + " def block(self, m_0,m_1,n_0,n_1):\n", + " myRows, myCols = self.shape()\n", + " if((m_0>=0 and m_1 <= myRows-1) and (n_0>=0 and n_1<= myCols-1)):\n", + " out=list()\n", + " for x in self.__data[m_0:m_1]:\n", + " out.append(x[n_0:n_1+1])\n", + " return out\n", + " else:\n", + " return None\n", + "\n", + " def M_scalarmul(self,c):\n", + " if(isinstance(c, int)==True or (isinstance(c,float)==True)):\n", + " out=list()\n", + " rows=len(self.__data)\n", + " cols=len(self.__data[0])\n", + " for i in range(rows):\n", + " row=list()\n", + " for j in range(cols):\n", + " row.append(c*self.__data[i][j])\n", + " out.append(row)\n", + " return out\n", + " else:\n", + " return None\n", + "\n", + " def M_add(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if(self.areCompatable(N)):\n", + " out=self.to_list()\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " out[i][j]=self.__data[i][j]+N[i][j]\n", + " return out\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_sub(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if(self.areCompatable(N)):\n", + " out=self.to_list()\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " out[i][j]=self.__data[i][j]-N[i][j]\n", + " return out\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_mat_mul(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " myRows, myCols = self.shape()\n", + " nRows, nCols = N.shape()\n", + " if( myCols==nRows ):\n", + " out=[[0]*nCols for i in range(myRows)]\n", + " for i in range(myRows):\n", + " for j in range(nCols):\n", + " for k in range(nRows):\n", + " out[i][j] += self.__data[i][k] * N[k][j]\n", + " return out\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_element_mul(self, N):\n", + " if(isinstance(N,Matrix)):\n", + " if(self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " out=self.to_list()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " out[i][j]=self.__data[i][j]*N[i][j]\n", + " return out\n", + " else:\n", + " return None\n", + "\n", + " def M_equal(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if (self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " if (self.__data[i][j] != N[i][j]):\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " \n", + " return True\n", + "\n", + "\n", + "\n", + "\n", + " def __str__(self):\n", + " return '\\n'.join(map(str, self.__data)) \n", + " \n", + " def __getitem__(self, index):\n", + " if (isinstance(index,int)):\n", + " return self.__data[index]\n", + " elif (isinstance(index,tuple)):\n", + " row, col = index\n", + " return self.__data[row][col]\n", + " else:\n", + " return None \n", + " \n", + " def __eq__(self, compare):\n", + " return self.areEqual(compare)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "3TxG8rvcwG3P", + "colab_type": "code", + "outputId": "4038124c-d9a6-474e-8c93-ea05a901ccb7", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 153 + } + }, + "source": [ + "m1=Matrix(2,2,2)\n", + "m2=Matrix(2,3,5)\n", + "print(\"Matrix 1:\",m1)\n", + "print(\"Matrix 2:\", m2)\n", + "\n", + "print(\"\\nScalar Multi. M1*4:\",m1.M_scalarmul(4))\n", + "print(\"\\nScalar Multi. M2*3:\", m2.M_scalarmul(3))" + ], + "execution_count": 123, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [2, 2]\n", + "[2, 2]\n", + "Matrix 2: [5, 5, 5]\n", + "[5, 5, 5]\n", + "\n", + "Scalar Multi. M1*4: [[8, 8], [8, 8]]\n", + "\n", + "Scalar Multi. M2*3: [[15, 15, 15], [15, 15, 15]]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "td53WVicmPK9", + "colab_type": "code", + "outputId": "6fe20c19-3789-4fdd-91a1-4f2b4b1229b0", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + } + }, + "source": [ + "mat1=Matrix(2,2,5)\n", + "mat2=Matrix(2,2,[[1,2],[3,4]])\n", + "mat3=Matrix(2,3,4)\n", + "print(\"Matrix 1:\",mat1)\n", + "print(\"Matrix 2:\", mat2)\n", + "print(\"Matrix 3:\", mat3)\n", + "\n", + "print(\"\\nMatrix Addition M1+M2:\", mat1.M_add(mat2), \"\\n\")\n", + "print(\"Matrix Addition M1+M3:\",mat1.M_add(mat3))\n" + ], + "execution_count": 124, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [5, 5]\n", + "[5, 5]\n", + "Matrix 2: [1, 2]\n", + "[3, 4]\n", + "Matrix 3: [4, 4, 4]\n", + "[4, 4, 4]\n", + "\n", + "Matrix Addition M1+M2: [[6, 7], [8, 9]] \n", + "\n", + "Matrix Addition M1+M3: None\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "LH-fWOG0oURf", + "colab_type": "code", + "outputId": "4ed48ea1-0bb6-438f-b626-fb62a316a865", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 255 + } + }, + "source": [ + "m1=Matrix(3,3,5)\n", + "m2=Matrix(3,3,2)\n", + "m3=Matrix(4,3,2)\n", + "print(\"Matrix 1:\", m1)\n", + "print(\"Matrix 2:\", m2)\n", + "print(\"Matrix 3:\", m3)\n", + "\n", + "print(\"\\nMatrix Subtraction: M1-M2:\", m1.M_sub(m2))\n", + "print(\"\\nMatrix Subtraction M1-M3:\", m1.M_sub(m3))" + ], + "execution_count": 125, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [5, 5, 5]\n", + "[5, 5, 5]\n", + "[5, 5, 5]\n", + "Matrix 2: [2, 2, 2]\n", + "[2, 2, 2]\n", + "[2, 2, 2]\n", + "Matrix 3: [2, 2, 2]\n", + "[2, 2, 2]\n", + "[2, 2, 2]\n", + "[2, 2, 2]\n", + "\n", + "Matrix Subtraction: M1-M2: [[3, 3, 3], [3, 3, 3], [3, 3, 3]]\n", + "\n", + "Matrix Subtraction M1-M3: None\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "40nFark2psjo", + "colab_type": "code", + "outputId": "a7c8ddb5-d2bb-4d78-9041-f92c78a3700f", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 204 + } + }, + "source": [ + "m1=Matrix(2,2,[[1,2],[3,4,]])\n", + "m2=Matrix(2,3,3)\n", + "m3=Matrix(3,2,4)\n", + "print(\"Matrix 1:\", m1)\n", + "print(\"Matrix 2:\", m2)\n", + "print(\"Matrix 3:\", m3)\n", + "\n", + "print(\"\\nMatrix Multi. M1*M2:\", m1.M_mat_mul(m2))\n", + "print(\"\\nMatrix Multi. M1*M3:\", m1.M_mat_mul(m3))" + ], + "execution_count": 126, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [1, 2]\n", + "[3, 4]\n", + "Matrix 2: [3, 3, 3]\n", + "[3, 3, 3]\n", + "Matrix 3: [4, 4]\n", + "[4, 4]\n", + "[4, 4]\n", + "\n", + "Matrix Multi. M1*M2: [[9, 9, 9], [21, 21, 21]]\n", + "\n", + "Matrix Multi. M1*M3: None\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "7e4EqHyupsmQ", + "colab_type": "code", + "outputId": "62d81f57-a512-4932-80d2-9f9d9d1fe17a", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + } + }, + "source": [ + "data=[[1,2],[3,4]]\n", + "m1=Matrix(2,2,data)\n", + "m2=Matrix(2,2,3)\n", + "m3=Matrix(2,3,4)\n", + "print(\"Matrix 1:\", m1)\n", + "print(\"Matrix 2:\", m2)\n", + "print(\"Matrix 3:\", m3)\n", + "\n", + "print(\"\\nElement mult. M1*M2:\", m1.M_element_mul(m2))\n", + "print(\"\\nElement mult. M1*M3:\", m1.M_element_mul(m3))" + ], + "execution_count": 127, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [1, 2]\n", + "[3, 4]\n", + "Matrix 2: [3, 3]\n", + "[3, 3]\n", + "Matrix 3: [4, 4, 4]\n", + "[4, 4, 4]\n", + "\n", + "Element mult. M1*M2: [[3, 6], [9, 12]]\n", + "\n", + "Element mult. M1*M3: None\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "L3t7ZBx2psoN", + "colab_type": "code", + "outputId": "3dc5c966-7a7f-41bc-9b01-6b4d6ed07b52", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 187 + } + }, + "source": [ + "m1=Matrix(2,2,[[1,2],[3,4]])\n", + "m2=Matrix(2,2,[[1,2],[3,4]])\n", + "m3=Matrix(2,2,4)\n", + "print(\"Matrix 1:\", m1)\n", + "print(\"Matrix 2:\", m2)\n", + "print(\"Matrix 3:\", m3)\n", + "\n", + "print(\"\\nMatrix equality M1==M2:\", m1.M_equal(m2))\n", + "print(\"\\nMatrix equality M1==M3:\", m1.M_equal(m3))" + ], + "execution_count": 128, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1: [1, 2]\n", + "[3, 4]\n", + "Matrix 2: [1, 2]\n", + "[3, 4]\n", + "Matrix 3: [4, 4]\n", + "[4, 4]\n", + "\n", + "Matrix equality M1==M2: True\n", + "\n", + "Matrix equality M1==M3: False\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "qzF8yeeTdhn8", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "fx90OofGuYmU", + "colab_type": "code", + "colab": {} + }, + "source": [ + "class Matrix:\n", + " __data=list()\n", + "\n", + " def __init__(self, m, n, fillVal=0):\n", + " if (isinstance(fillVal, list)):\n", + " check = True\n", + " if (len(fillVal)==m):\n", + " for element in (fillVal):\n", + " if (len(element)!=n):\n", + " isGood = False\n", + " break\n", + "\n", + " if (check):\n", + " self.__data = []\n", + " for element in (fillVal):\n", + " self.__data.append(element)\n", + " else:\n", + " if (n>=0 and m>=0):\n", + " self.__data = [[fillVal]*n for iter in range(m)]\n", + " \n", + " \n", + " def shape(self):\n", + " return((len(self.__data), len(self.__data[0])))\n", + " \n", + " def areCompatable(self, testM):\n", + " if (isinstance(testM, Matrix)):\n", + " rows, cols = testM.shape()\n", + " myRows, myCols = self.shape()\n", + " if (myRows == rows and myCols == cols ):\n", + " return True\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + "\n", + " def transpose(self):\n", + " rows=len(self.__data)\n", + " cols=len(self.__data[0])\n", + " out=list()\n", + " for i in range(rows):\n", + " row=list()\n", + " for j in range(cols):\n", + " row.append(self.__data[j][i])\n", + " out.append(row)\n", + " return out\n", + "\n", + " #for row(n) im assuming Dr.Farbin means take the nth row and convert it to a (length of row)x1 matrix\n", + " #ex: 3x3 matrix ==> nth row would be converted to a 3x1 matrix\n", + " def row(self, n):\n", + " out=list()\n", + " x=self.__data[n]\n", + "\n", + " for i in range(len(x)):\n", + " rows=list()\n", + " for j in range(0,1):\n", + " rows.append(x[i])\n", + " out.append(rows)\n", + " return out\n", + " \n", + " #for column(n) im assuming Dr.Farbin means take the nth col and convert it to 1x(# of rows in column) matrix\n", + " def column(self, n):\n", + " out=list()\n", + " \n", + " for i in range(len(self.__data)):\n", + " for j in range(len(self.__data[i])):\n", + " out.append(self.__data[i][n])\n", + " break\n", + " return out\n", + "\n", + " def to_list(self):\n", + " return list(self.__data)\n", + "\n", + " def block(self, m_0,m_1,n_0,n_1):\n", + " myRows, myCols = self.shape()\n", + " if((m_0>=0 and m_1 <= myRows-1) and (n_0>=0 and n_1<= myCols-1)):\n", + " out=list()\n", + " for x in self.__data[m_0:m_1]:\n", + " out.append(x[n_0:n_1+1])\n", + " return out\n", + " else:\n", + " return None\n", + "\n", + " def M_scalarmul(self,c):\n", + " if(isinstance(c, int)==True or (isinstance(c,float)==True)):\n", + " rows=len(self.__data)\n", + " cols=len(self.__data[0])\n", + " outM=Matrix(rows,cols)\n", + " for i in range(rows):\n", + " for j in range(cols):\n", + " outM[i][j]=c*self.__data[i][j]\n", + " return outM\n", + " else:\n", + " return None\n", + "\n", + " def M_add(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if(self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " outM=Matrix(myRows,myCols)\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " outM[i][j]=self.__data[i][j]+N[i][j]\n", + " return outM\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_sub(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if(self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " outM=Matrix(myRows,myCols)\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " outM[i][j]=self.__data[i][j]-N[i][j]\n", + " return outM\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_mat_mul(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " myRows, myCols = self.shape()\n", + " nRows, nCols = N.shape()\n", + " if( myCols==nRows ):\n", + " outM=Matrix(myRows,myCols)\n", + " for i in range(myRows):\n", + " for j in range(nCols):\n", + " for k in range(nRows):\n", + " outM[i][j] += self.__data[i][k] * N[k][j]\n", + " return outM\n", + " else:\n", + " return None\n", + " else:\n", + " return None\n", + "\n", + " def M_element_mul(self, N):\n", + " if(isinstance(N,Matrix)):\n", + " if(self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " outM=Matrix(myRows,myCols)\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " outM[i][j]=self.__data[i][j]*N[i][j]\n", + " return outM\n", + " else:\n", + " return None\n", + "\n", + " def M_equal(self, N):\n", + " if (isinstance(N, Matrix)):\n", + " if (self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " if (self.__data[i][j] != N[i][j]):\n", + " return False\n", + " else:\n", + " return False\n", + " else:\n", + " return False\n", + " \n", + " return True\n", + "\n", + " def set_equal(self, N):\n", + " if (isinstance(N,Matrix)):\n", + " if(self.areCompatable(N)):\n", + " myRows, myCols = self.shape()\n", + " for i in range(myRows):\n", + " for j in range(myCols):\n", + " self.__data[i][j]=N[i][j]\n", + " else:\n", + " print(\"Matrices must be same dimension\")\n", + " else:\n", + " return None\n", + "\n", + " return self.__data\n", + "\n", + "\n", + "\n", + "\n", + " def __str__(self):\n", + " return '\\n'.join(map(str, self.__data)) \n", + " \n", + " def __getitem__(self, index):\n", + " if (isinstance(index,int)):\n", + " return self.__data[index]\n", + " elif (isinstance(index,tuple)):\n", + " row, col = index\n", + " return self.__data[row][col]\n", + " else:\n", + " return None \n", + " \n", + " def __eq__(self, compare):\n", + " return self.M_equal(compare)\n", + "\n", + " def __seq__(self, compare):\n", + " return self.set_equal(compare)\n", + "\n", + " def __add__(self, other):\n", + " return self.M_add(other)\n", + " \n", + " def __sub__(self, other):\n", + " return self.M_sub(other)\n", + "\n", + " def __mul__(self,other):\n", + " if(isinstance(other, Matrix)):\n", + " return self.M_mat_mul(other)\n", + " else:\n", + " return self.M_scalarmul(other)" + ], + "execution_count": 0, + "outputs": [] + }, + { + "cell_type": "code", + "metadata": { + "id": "0oi_YvcYFPJU", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 697 + }, + "outputId": "0594839b-1094-44ea-c50f-27b99fa52d21" + }, + "source": [ + "m1 = Matrix(4,4,5)\n", + "m2 = Matrix(4,4,6)\n", + "print('Matrix 1:\\n', m1)\n", + "print(\"Matrix 2:\\n\", m2)\n", + "\n", + "print('\\nM1*2')\n", + "r1 = m1*2\n", + "print(r1)\n", + "\n", + "print('\\n2*M1')\n", + "r1 = m1*2\n", + "print(r1)\n", + "\n", + "r2=m1+m2\n", + "print(\"\\nM1+M2:\\n\",r2)\n", + "\n", + "r3=m2-m1\n", + "print(\"\\nM2-M1:\\n\", r3)\n", + "\n", + "print(\"\\nM1==M2:\\n\", m1==m2)\n", + "\n", + "print(\"\\nM1=M2:\\nNew Matrix 1:\", m1.set_equal(m2))" + ], + "execution_count": 133, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix 1:\n", + " [5, 5, 5, 5]\n", + "[5, 5, 5, 5]\n", + "[5, 5, 5, 5]\n", + "[5, 5, 5, 5]\n", + "Matrix 2:\n", + " [6, 6, 6, 6]\n", + "[6, 6, 6, 6]\n", + "[6, 6, 6, 6]\n", + "[6, 6, 6, 6]\n", + "\n", + "M1*2\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "\n", + "2*M1\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "[10, 10, 10, 10]\n", + "\n", + "M1+M2:\n", + " [11, 11, 11, 11]\n", + "[11, 11, 11, 11]\n", + "[11, 11, 11, 11]\n", + "[11, 11, 11, 11]\n", + "\n", + "M2-M1:\n", + " [1, 1, 1, 1]\n", + "[1, 1, 1, 1]\n", + "[1, 1, 1, 1]\n", + "[1, 1, 1, 1]\n", + "\n", + "M1==M2:\n", + " False\n", + "\n", + "M1=M2:\n", + "New Matrix 1: [[6, 6, 6, 6], [6, 6, 6, 6], [6, 6, 6, 6], [6, 6, 6, 6]]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "markdown", + "metadata": { + "id": "9CPWxgxgdhn8", + "colab_type": "text" + }, + "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", + "metadata": { + "id": "ZmXfUipydhn9", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 170 + }, + "outputId": "99edd0d6-3145-41a6-f287-0c2994232919" + }, + "source": [ + "matrixA=Matrix(2,2,3)\n", + "matrixB=Matrix(2,2,4)\n", + "matrixC=Matrix(2,2,2)\n", + "print('Matrix A:\\n', matrixA)\n", + "print(\"Matrix B:\\n\", matrixB)\n", + "print(\"Matrix C:\\n\", matrixC)" + ], + "execution_count": 131, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Matrix A:\n", + " [3, 3]\n", + "[3, 3]\n", + "Matrix B:\n", + " [4, 4]\n", + "[4, 4]\n", + "Matrix C:\n", + " [2, 2]\n", + "[2, 2]\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "IckvLQGqUDxQ", + "colab_type": "code", + "colab": { + "base_uri": "https://localhost:8080/", + "height": 867 + }, + "outputId": "1e18c21f-c505-43bf-e182-ade4269a0ae1" + }, + "source": [ + "AB=matrixA*matrixB\n", + "AB_C=AB*matrixC\n", + "print(\"Testing (AB)C=A(BC):\")\n", + "print(\"(AB)C:\\n\", AB_C)\n", + "A_BC=matrixA*(matrixB*matrixC)\n", + "print(\"\\nA(BC):\\n\", A_BC)\n", + "print(\"\\n(AB)C=A(BC):\\n\", AB_C==A_BC)\n", + "\n", + "\n", + "print(\"\\n\\nTesting A(B+C)=AB+AC:\")\n", + "A_BpC=matrixA*(matrixB+matrixC)\n", + "print(\"A(B+C):\\n\", A_BpC)\n", + "AB_AC=(matrixA*matrixB)+(matrixA*matrixC)\n", + "print(\"\\nAB+AC:\\n\", AB_AC)\n", + "print(\"\\nA(B+C)=AB+AC:\\n\", A_BpC==AB_AC)\n", + "\n", + "\n", + "print(\"\\n\\nTesting 𝐴𝐵≠𝐵𝐴:\")\n", + "BA=matrixA*matrixB\n", + "print(\"AB:\\n\", AB)\n", + "print(\"\\nBA:\\n\", BA)\n", + "print(\"\\n𝐴𝐵≠𝐵𝐴:\\n\", AB==BA)\n", + "\n", + "\n", + "print(\"\\n\\nTesting AI=A:\")\n", + "I=eye(2)\n", + "AI=matrixA*I\n", + "print(\"AI:\\n\",AI)\n", + "print(\"\\nA:\\n\", matrixA)\n", + "print(\"\\nAI=A:\\n\", AI==matrixA)" + ], + "execution_count": 132, + "outputs": [ + { + "output_type": "stream", + "text": [ + "Testing (AB)C=A(BC):\n", + "(AB)C:\n", + " [96, 96]\n", + "[96, 96]\n", + "\n", + "A(BC):\n", + " [96, 96]\n", + "[96, 96]\n", + "\n", + "(AB)C=A(BC):\n", + " True\n", + "\n", + "\n", + "Testing A(B+C)=AB+AC:\n", + "A(B+C):\n", + " [36, 36]\n", + "[36, 36]\n", + "\n", + "AB+AC:\n", + " [36, 36]\n", + "[36, 36]\n", + "\n", + "A(B+C)=AB+AC:\n", + " True\n", + "\n", + "\n", + "Testing 𝐴𝐵≠𝐵𝐴:\n", + "AB:\n", + " [24, 24]\n", + "[24, 24]\n", + "\n", + "BA:\n", + " [24, 24]\n", + "[24, 24]\n", + "\n", + "𝐴𝐵≠𝐵𝐴:\n", + " True\n", + "\n", + "\n", + "Testing AI=A:\n", + "AI:\n", + " [3, 3]\n", + "[3, 3]\n", + "\n", + "A:\n", + " [3, 3]\n", + "[3, 3]\n", + "\n", + "AI=A:\n", + " True\n" + ], + "name": "stdout" + } + ] + }, + { + "cell_type": "code", + "metadata": { + "id": "OgOhZ40vxd_x", + "colab_type": "code", + "colab": {} + }, + "source": [ + "" + ], + "execution_count": 0, + "outputs": [] + } + ] +} \ No newline at end of file diff --git a/Labs/Lab-7/Lab_7_Solutions.ipynb b/Labs/Lab-7/Lab_7_Solutions.ipynb new file mode 100644 index 0000000..c38442b --- /dev/null +++ b/Labs/Lab-7/Lab_7_Solutions.ipynb @@ -0,0 +1,3493 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "qJJhiNjL04bS" + }, + "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": 423, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "fwQXzdy104bT" + }, + "outputs": [], + "source": [ + "import numpy as np\n", + "import math\n", + "\n", + "# Create some virtual classes\n", + "class base:\n", + " __name=\"\"\n", + " \n", + " def __init__(self,name):\n", + " self.__name=name\n", + "\n", + " def name(self):\n", + " return self.__name\n", + "\n", + "class data(base):\n", + " def __init__(self,name):\n", + " base.__init__(self,name)\n", + " \n", + "class alg(base):\n", + " def __init__(self,name):\n", + " base.__init__(self,name)" + ] + }, + { + "cell_type": "code", + "execution_count": 424, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "-EEV3T1804bW" + }, + "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,raw=True):\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", + " \n", + " self.__gradebook_name=name\n", + " data.__init__(self,name+\" Grade Algorithm\") \n", + "\n", + " \n", + " def set(self,value):\n", + " if isinstance(value,(int,float)) and self.__numerical:\n", + " self.__value=value\n", + " elif isinstance(value,str) and not self.__numerical:\n", + " if value in self.__letter_grades:\n", + " self.__value=value\n", + " else:\n", + " print (self.name()+\" Error: Bad Grade.\")\n", + " raise Exception\n", + " \n", + " def value(self):\n", + " return self.__value\n", + " \n", + " def numerical(self):\n", + " return self.__numerical\n", + " \n", + " def gradebook_name(self):\n", + " return self.__gradebook_name\n", + " \n", + " def __str__(self):\n", + " return self.__gradebook_name+\": \"+str(self.__value)\n", + "\n", + "class student(data):\n", + " __id_number=0\n", + " __grades=dict()\n", + " \n", + " def __init__(self,first_name, last_name,id_number):\n", + " self.__id_number=id_number\n", + " self.__grades=dict()\n", + " data.__init__(self,first_name+\" \"+last_name+\" Student Data\")\n", + "\n", + " def add_grade(self,a_grade,overwrite=False):\n", + " if overwrite or not a_grade.gradebook_name() in self.__grades:\n", + " self.__grades[a_grade.gradebook_name()]=a_grade\n", + " else:\n", + " print (self.name()+\" Error Adding Grade \"+a_grade.name()+\". Grade already exists.\")\n", + " raise Exception\n", + " \n", + "\n", + " def id_number(self):\n", + " return self.__id_number\n", + " \n", + " def print_grades(self):\n", + " for grade in self.__grades:\n", + " print (self.__grades[grade]) \n", + " \n", + " def __str__(self):\n", + " return str(self.__id_number)+\" \"+str(self.__grades)\n", + " \n", + " def __getitem__(self,key):\n", + " return self.__grades[key]\n", + " \n" + ] + }, + { + "cell_type": "code", + "execution_count": 425, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "s7cZZxRV04bZ" + }, + "outputs": [], + "source": [ + "class calculator(alg): \n", + " def __init__(self,name):\n", + " alg.__init__(self,name)\n", + "\n", + " def apply(self,a_grade_book):\n", + " raise NotImplementedError\n" + ] + }, + { + "cell_type": "code", + "execution_count": 426, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "c0XFb-JG04bb" + }, + "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", + " __assignments=list()\n", + " \n", + " def __init__(self,name):\n", + " data.__init__(self,name+\" Course Grade Book\")\n", + " self.__students=dict()\n", + " self.__data=dict()\n", + " \n", + " # New method to access data\n", + " def __getitem__(self,key):\n", + " return self.__data[key]\n", + " \n", + " # New method to add data\n", + " def __setitem__(self, key, value):\n", + " self.__data[key] = value\n", + " \n", + " def add_student(self,a_student):\n", + " self.__students[a_student.id_number()]=a_student\n", + "\n", + " # New method to allow iterating over students\n", + " def get_students(self):\n", + " return self.__students\n", + " \n", + " def assign_grade(self,key,a_grade):\n", + " the_student=None\n", + " try:\n", + " the_student=self.__students[key]\n", + " except:\n", + " for id in self.__students:\n", + " if key == self.__students[id].name():\n", + " the_student=self.__students[id]\n", + " break\n", + " if the_student:\n", + " the_student.add_grade(a_grade)\n", + " else:\n", + " print (self.name()+\" Error: Did not find student.\")\n", + " \n", + " def apply_calculator(self,a_calculator,**kwargs):\n", + " # a_calculator object is instantiated when invoking the apply_calculator method\n", + " a_calculator.apply(self,**kwargs)\n", + " \n", + " def summarize_all(self):\n", + " #summarize all assignments for all students\n", + " pass\n", + " \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", + " \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_stats(self):\n", + " #the __data dict can hold misc sata so make sure we print correct stats\n", + " for k, v in self.__data.items():\n", + " if isinstance (k,str):\n", + " if(\"Mean\" in k):\n", + " print(k+\": \",str(round(v,2)))\n", + " if(\"STD\" in k):\n", + " print(k+\": \",str(round(v,2)))\n", + " \n", + " \n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 427, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "ZxpFgYpa04bd" + }, + "outputs": [], + "source": [ + "class uncurved_letter_grade_percent(calculator):\n", + " __grades_definition=[ (.97,\"A+\"),\n", + " (.93,\"A\"),\n", + " (.9,\"A-\"),\n", + " (.87,\"B+\"),\n", + " (.83,\"B\"),\n", + " (.8,\"B-\"),\n", + " (.77,\"C+\"),\n", + " (.73,\"C\"),\n", + " (.7,\"C-\"),\n", + " (.67,\"C+\"),\n", + " (.63,\"C\"),\n", + " (.6,\"C-\"),\n", + " (.57,\"F+\"),\n", + " (.53,\"F\"),\n", + " (0.,\"F-\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,grade_name,max_grade=100.):\n", + " self.__max_grade=max_grade\n", + " self.__grade_name=grade_name\n", + " calculator.__init__(self,\n", + " \"Uncurved Percent Based Grade Calculator \"+self.__grade_name+\" Max=\"+str(self.__max_grade))\n", + " \n", + " def apply(self,a_grade_book,grade_name=None,**kwargs):\n", + " if grade_name:\n", + " pass\n", + " else:\n", + " grade_name=self.__grade_name\n", + " \n", + " \n", + " #iterate through the students and grab the selected grades\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", + " \n", + " #print('add Letter: '+ grade_name+\" Letter\" + self.__grades_definition[i][1] )\n", + " \n", + " new_name = grade_name.replace(\"sum\",\"Uncurved Letter\")\n", + " a_student.add_grade(grade(new_name,value=self.__grades_definition[i][1]),overwrite=True)\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 428, + "metadata": {}, + "outputs": [], + "source": [ + "class mean_std_calculator(calculator):\n", + " def __init__(self):\n", + " calculator.__init__(self,\"Mean and Standard Deviation Calculator\")\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", + " \n", + " #i didnt know where to put these calc and this is an easy place\n", + " a_grade_book[grade_name+\" Max\"] = max(grades)\n", + " a_grade_book[grade_name+\" Min\"] = min(grades)" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "collapsed": true, + "id": "j8z9vxan04bi" + }, + "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": 429, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "id": "jQ1WAU7uVIhF", + "outputId": "5c3aea5c-8ba0-4ec4-eec9-8e7e819fe7f1" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Copy_of_Lab_7.ipynb Data1401-Grades.txt\r\n" + ] + } + ], + "source": [ + "!ls" + ] + }, + { + "cell_type": "code", + "execution_count": 430, + "metadata": { + "colab": { + "base_uri": "https://localhost:8080/", + "height": 34 + }, + "colab_type": "code", + "id": "tqqpBEuj04bi", + "outputId": "ba90e0e6-8d75-44e2-8a4e-103c281e4d78" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n", + "\r\n" + ] + } + ], + "source": [ + "!cat Data1401-Grades.txt" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "2cDDfieQ04bm" + }, + "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": 431, + "metadata": {}, + "outputs": [], + "source": [ + "def csv_reader(filename, structureType=\"ListOfLists\", header=True):\n", + " outDataFormats = [\"DictOfLists\",\"ListOfLists\", \"ListOfDicts\"]\n", + "\n", + " if (structureType in outDataFormats):\n", + "\n", + " f=open(filename,\"r\")\n", + "\n", + " if (header):\n", + " first_line = f.readline().rstrip()\n", + " fields=first_line.split(\",\")\n", + "\n", + " if (structureType==\"DictOfLists\"):\n", + " data=dict()\n", + " for keyNames in fields: \n", + " data[keyNames] = list()\n", + " else:\n", + " data=list() \n", + " \n", + " line = f.readline().rstrip()\n", + "\n", + " while line:\n", + " items=line.split(\",\")\n", + "\n", + " if (structureType==\"ListOfDicts\"):\n", + " row=dict()\n", + " else:\n", + " row=list()\n", + "\n", + " colCount=0\n", + "\n", + " for item in items:\n", + " try:\n", + " d=float(item)\n", + " except ValueError:\n", + " d=item\n", + " \n", + " # Store according to the structure in use\n", + " if (structureType==\"ListOfDicts\"):\n", + " # append the dictionary to the list\n", + " row[fields[colCount]]=d\n", + " elif (structureType==\"DictOfLists\"):\n", + " data[fields[colCount]].append(d) \n", + " else:\n", + " row.append(d)\n", + " colCount += 1\n", + " \n", + " if (structureType==\"ListOfDicts\"):\n", + " #Adding this list as sublist in myDict\n", + " data.append(row) \n", + " elif (structureType==\"ListOfLists\"):\n", + " data.append(row)\n", + " \n", + " line = f.readline().rstrip()\n", + "\n", + " f.close() \n", + " \n", + " if (structureType==\"ListOfLists\"):\n", + " return data, fields\n", + " else:\n", + " return data\n", + " else:\n", + " return None" + ] + }, + { + "cell_type": "code", + "execution_count": 432, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "As a List of Lists: \n", + "Keys: \n", + " ['l1_n', 'l1_1', '12_n', 'l2_1', 'l2_2', 'l2_3', 'l2_4', 'l2_5', 'l2_6', 'l2_7', 'l3_n', 'l3_1', 'l3_2', 'l3_3', 'l3_4', 'l3_5', 'l3_6', 'l3_7', 'l3_8', 'l3_9', 'l3_10', 'l3_11', 'l3_12', 'l3_13', 'l3_14', 'l4_n', 'l4_1', 'l4_2', 'l4_3', 'l4_4', 'l4_5', 'l4_6', 'l4_7', 'l4_8', 'l4_9', 'l4_10', 'l4_11', 'q1_n', 'q1_1', 'e1_n', 'e1_1', 'e1_2', 'e1_3', 'e1_4', 'e1_5', 'e1_6', 'e1_7', 'e1_8', 'e1_9', 'e1_10', 'e1_11', 'e1_12', 'e1_13', 'e1_14', 'e1_15'] \n", + "Data:\n", + " [1.0, 10.0, 7.0, 0.0, 10.0, 10.0, 8.0, 10.0, 10.0, 10.0, 14.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 0.0, 9.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 14.0, 9.0, 10.0, 10.0, 10.0, 7.0, 10.0, 3.0, 6.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 15.0, 5.0, 5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 3.0, 9.5, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 8.0, 5.0, 10.0, 5.0, 10.0, 3.0, 0.0, 10.0, 3.0, 10.0, 8.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 10.0, 5.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 7.0, 9.0, 0.0, 0.0, 10.0, 10.0, 9.0, 5.0, 10.0, 8.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 9.5, 0.0, 0.0, 10.0, 0.0, 10.0, 5.0, 10.0, 7.0, 0.0, 10.0, 6.0, 10.0, 0.0, 11.0, 10.0, 10.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 7.0, 0.0, 3.0, 3.0, 3.0, 0.0, 3.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 10.0, 9.5, 10.0, 10.0, 9.5, 14.0, 5.0, 9.5, 9.5, 8.0, 10.0, 10.0, 8.0, 10.0, 8.0, 0.0, 5.0, 6.0, 0.0, 0.0, 11.0, 0.0, 10.0, 10.0, 10.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 9.0, 9.0, 10.0, 7.0, 0.0, 9.0, 9.0, 9.0, 0.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 5.0, 10.0, 10.0, 9.5, 14.0, 9.5, 10.0, 10.0, 8.0, 10.0, 8.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 10.0, 9.5, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 3.0, 3.0, 0.0, 0.0, 5.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 0.0, 10.0, 0.0, 7.0, 5.0, 9.0, 9.0, 9.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 5.0, 3.0, 0.0, 3.0, 10.0, 7.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 5.0, 10.0, 0.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 10.0, 10.0, 10.0, 10.0, 14.0, 10.0, 6.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 9.0, 5.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 5.0, 10.0, 5.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 7.0, 14.0, 10.0, 10.0, 10.0, 10.0, 7.0, 10.0, 6.0, 3.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 5.0, 10.0, 10.0, 10.0, 10.0, 10.0, 1.0, 0.0, 15.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 5.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 9.5, 10.0, 10.0, 9.5, 14.0, 9.5, 10.0, 10.0, 10.0, 8.0, 10.0, 8.0, 10.0, 10.0, 7.0, 5.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 8.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 5.0, 9.5, 10.0, 10.0, 9.5, 14.0, 5.0, 9.0, 9.0, 10.0, 7.0, 10.0, 10.0, 10.0, 10.0, 7.0, 10.0, 3.0, 5.0, 10.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 9.0, 8.0, 7.0, 10.0, 0.0, 9.0, 10.0, 9.0, 10.0, 9.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 9.5, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 10.0, 5.0, 10.0, 10.0, 11.0, 0.0, 10.0, 10.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 9.0, 9.0, 10.0, 0.0, 8.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 9.0, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 10.0, 3.0, 0.0, 3.0, 3.0, 5.0, 2.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 9.0, 9.0, 10.0, 5.0, 5.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 5.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 3.0, 7.0, 10.0, 10.0, 9.0, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 9.0, 10.0, 7.0, 7.0, 3.0, 7.0, 5.0, 8.0, 11.0, 10.0, 10.0, 10.0, 8.0, 5.0, 3.0, 0.0, 0.0, 7.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 10.0, 7.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 8.0, 2.0]\n", + "\n", + "As a Dict of Lists:\n", + "l1_n : [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\n", + "l1_1 : [10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "12_n : [7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0, 7.0]\n", + "l2_1 : [0.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_2 : [10.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_3 : [10.0, 0.0, 0.0, 3.0, 9.5, 10.0, 0.0, 10.0, 9.5, 0.0, 0.0, 9.5, 5.0, 9.5, 9.5, 3.0]\n", + "l2_4 : [8.0, 0.0, 0.0, 9.5, 0.0, 9.5, 5.0, 9.5, 0.0, 10.0, 0.0, 9.5, 9.5, 0.0, 9.0, 7.0]\n", + "l2_5 : [10.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_6 : [10.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l2_7 : [10.0, 0.0, 0.0, 9.5, 0.0, 9.5, 9.5, 9.5, 0.0, 10.0, 7.0, 9.5, 9.5, 0.0, 9.5, 9.0]\n", + "l3_n : [14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0, 14.0]\n", + "l3_1 : [9.0, 0.0, 9.0, 10.0, 9.5, 5.0, 9.5, 10.0, 10.0, 10.0, 10.0, 9.5, 5.0, 9.5, 10.0, 10.0]\n", + "l3_2 : [0.0, 0.0, 10.0, 10.0, 0.0, 9.5, 10.0, 10.0, 10.0, 6.0, 10.0, 10.0, 9.0, 10.0, 10.0, 10.0]\n", + "l3_3 : [0.0, 0.0, 10.0, 10.0, 0.0, 9.5, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 10.0, 10.0, 10.0]\n", + "l3_4 : [0.0, 0.0, 10.0, 8.0, 10.0, 8.0, 8.0, 10.0, 10.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l3_5 : [0.0, 0.0, 7.0, 5.0, 0.0, 10.0, 10.0, 0.0, 0.0, 0.0, 7.0, 8.0, 7.0, 10.0, 10.0, 0.0]\n", + "l3_6 : [0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 8.0, 0.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l3_7 : [0.0, 0.0, 3.0, 5.0, 5.0, 8.0, 9.0, 0.0, 0.0, 0.0, 6.0, 8.0, 10.0, 10.0, 9.0, 9.0]\n", + "l3_8 : [0.0, 0.0, 6.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 3.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "l3_9 : [0.0, 0.0, 3.0, 3.0, 7.0, 8.0, 0.0, 0.0, 0.0, 0.0, 10.0, 10.0, 10.0, 0.0, 3.0, 7.0]\n", + "l3_10 : [0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 7.0, 7.0, 0.0, 0.0, 7.0]\n", + "l3_11 : [0.0, 0.0, 0.0, 10.0, 10.0, 5.0, 0.0, 0.0, 0.0, 0.0, 10.0, 5.0, 10.0, 10.0, 3.0, 3.0]\n", + "l3_12 : [0.0, 0.0, 0.0, 3.0, 6.0, 6.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 3.0, 5.0, 3.0, 7.0]\n", + "l3_13 : [0.0, 0.0, 0.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 5.0, 10.0, 5.0, 5.0]\n", + "l3_14 : [0.0, 0.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 10.0, 10.0, 2.0, 8.0]\n", + "l4_n : [11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0, 11.0]\n", + "l4_1 : [0.0, 0.0, 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 10.0]\n", + "l4_2 : [0.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 0.0, 10.0]\n", + "l4_3 : [0.0, 0.0, 0.0, 10.0, 6.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 10.0, 0.0, 10.0, 0.0, 10.0]\n", + "l4_4 : [0.0, 0.0, 0.0, 10.0, 0.0, 10.0, 0.0, 10.0, 10.0, 7.0, 10.0, 10.0, 0.0, 0.0, 0.0, 8.0]\n", + "l4_5 : [0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 3.0, 5.0, 0.0, 10.0, 5.0, 0.0, 0.0, 0.0, 5.0]\n", + "l4_6 : [0.0, 0.0, 0.0, 10.0, 0.0, 5.0, 10.0, 3.0, 3.0, 0.0, 5.0, 6.0, 0.0, 5.0, 0.0, 3.0]\n", + "l4_7 : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "l4_8 : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "l4_9 : [0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 5.0, 10.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 7.0]\n", + "l4_10 : [0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 7.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "l4_11 : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "q1_n : [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]\n", + "q1_1 : [9.5, 0.0, 5.0, 10.0, 0.0, 9.5, 10.0, 10.0, 9.5, 9.5, 0.0, 10.0, 10.0, 0.0, 0.0, 9.5]\n", + "e1_n : [15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0, 15.0]\n", + "e1_1 : [9.0, 0.0, 5.0, 9.0, 0.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0]\n", + "e1_2 : [9.0, 0.0, 5.0, 9.0, 0.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0]\n", + "e1_3 : [0.0, 0.0, 5.0, 10.0, 0.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 10.0, 9.0, 10.0, 10.0, 10.0]\n", + "e1_4 : [9.0, 0.0, 5.0, 9.0, 0.0, 9.0, 9.0, 0.0, 5.0, 9.0, 9.0, 9.0, 8.0, 0.0, 5.0, 10.0]\n", + "e1_5 : [8.0, 0.0, 0.0, 7.0, 5.0, 9.0, 0.0, 10.0, 10.0, 5.0, 9.0, 8.0, 7.0, 8.0, 5.0, 7.0]\n", + "e1_6 : [0.0, 0.0, 0.0, 9.0, 0.0, 10.0, 0.0, 0.0, 0.0, 9.0, 10.0, 9.0, 10.0, 9.0, 0.0, 10.0]\n", + "e1_7 : [0.0, 0.0, 0.0, 0.0, 7.0, 7.0, 0.0, 7.0, 9.0, 7.0, 9.0, 7.0, 0.0, 7.0, 0.0, 10.0]\n", + "e1_8 : [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 9.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 10.0]\n", + "e1_9 : [0.0, 0.0, 0.0, 10.0, 3.0, 9.0, 0.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "e1_10 : [0.0, 0.0, 0.0, 10.0, 3.0, 9.0, 0.0, 9.0, 9.0, 10.0, 10.0, 10.0, 9.0, 10.0, 10.0, 10.0]\n", + "e1_11 : [0.0, 0.0, 0.0, 9.0, 3.0, 9.0, 0.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0]\n", + "e1_12 : [0.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 10.0, 5.0, 10.0, 10.0, 9.0, 10.0, 0.0, 10.0]\n", + "e1_13 : [0.0, 0.0, 0.0, 10.0, 3.0, 5.0, 0.0, 0.0, 5.0, 10.0, 10.0, 0.0, 5.0, 10.0, 10.0, 9.0]\n", + "e1_14 : [0.0, 0.0, 0.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 5.0, 5.0, 0.0, 0.0, 0.0, 5.0, 8.0]\n", + "e1_15 : [0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 10.0, 2.0]\n", + "\n", + "As a List of Dicts:\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 0.0, 'l2_2': 10.0, 'l2_3': 10.0, 'l2_4': 8.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 10.0, 'l3_n': 14.0, 'l3_1': 9.0, 'l3_2': 0.0, 'l3_3': 0.0, 'l3_4': 0.0, 'l3_5': 0.0, 'l3_6': 0.0, 'l3_7': 0.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 0.0, 'l4_3': 0.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 9.5, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 0.0, 'e1_4': 9.0, 'e1_5': 8.0, 'e1_6': 0.0, 'e1_7': 0.0, 'e1_8': 0.0, 'e1_9': 0.0, 'e1_10': 0.0, 'e1_11': 0.0, 'e1_12': 0.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 0.0, 'l2_2': 0.0, 'l2_3': 0.0, 'l2_4': 0.0, 'l2_5': 0.0, 'l2_6': 0.0, 'l2_7': 0.0, 'l3_n': 14.0, 'l3_1': 0.0, 'l3_2': 0.0, 'l3_3': 0.0, 'l3_4': 0.0, 'l3_5': 0.0, 'l3_6': 0.0, 'l3_7': 0.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 0.0, 'l4_3': 0.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 0.0, 'e1_n': 15.0, 'e1_1': 0.0, 'e1_2': 0.0, 'e1_3': 0.0, 'e1_4': 0.0, 'e1_5': 0.0, 'e1_6': 0.0, 'e1_7': 0.0, 'e1_8': 0.0, 'e1_9': 0.0, 'e1_10': 0.0, 'e1_11': 0.0, 'e1_12': 0.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 0.0, 'l2_2': 0.0, 'l2_3': 0.0, 'l2_4': 0.0, 'l2_5': 0.0, 'l2_6': 0.0, 'l2_7': 0.0, 'l3_n': 14.0, 'l3_1': 9.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 7.0, 'l3_6': 10.0, 'l3_7': 3.0, 'l3_8': 6.0, 'l3_9': 3.0, 'l3_10': 3.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 0.0, 'l4_3': 0.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 5.0, 'e1_n': 15.0, 'e1_1': 5.0, 'e1_2': 5.0, 'e1_3': 5.0, 'e1_4': 5.0, 'e1_5': 0.0, 'e1_6': 0.0, 'e1_7': 0.0, 'e1_8': 0.0, 'e1_9': 0.0, 'e1_10': 0.0, 'e1_11': 0.0, 'e1_12': 0.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 3.0, 'l2_4': 9.5, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 8.0, 'l3_5': 5.0, 'l3_6': 10.0, 'l3_7': 5.0, 'l3_8': 10.0, 'l3_9': 3.0, 'l3_10': 0.0, 'l3_11': 10.0, 'l3_12': 3.0, 'l3_13': 10.0, 'l3_14': 8.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 10.0, 'l4_6': 10.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 10.0, 'l4_10': 5.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 10.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 9.0, 'e1_5': 7.0, 'e1_6': 9.0, 'e1_7': 0.0, 'e1_8': 0.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 9.0, 'e1_12': 5.0, 'e1_13': 10.0, 'e1_14': 8.0, 'e1_15': 10.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 9.5, 'l2_4': 0.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 0.0, 'l3_n': 14.0, 'l3_1': 9.5, 'l3_2': 0.0, 'l3_3': 0.0, 'l3_4': 10.0, 'l3_5': 0.0, 'l3_6': 10.0, 'l3_7': 5.0, 'l3_8': 10.0, 'l3_9': 7.0, 'l3_10': 0.0, 'l3_11': 10.0, 'l3_12': 6.0, 'l3_13': 10.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 6.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 0.0, 'e1_n': 15.0, 'e1_1': 0.0, 'e1_2': 0.0, 'e1_3': 0.0, 'e1_4': 0.0, 'e1_5': 5.0, 'e1_6': 0.0, 'e1_7': 7.0, 'e1_8': 0.0, 'e1_9': 3.0, 'e1_10': 3.0, 'e1_11': 3.0, 'e1_12': 0.0, 'e1_13': 3.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 10.0, 'l2_4': 9.5, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 5.0, 'l3_2': 9.5, 'l3_3': 9.5, 'l3_4': 8.0, 'l3_5': 10.0, 'l3_6': 10.0, 'l3_7': 8.0, 'l3_8': 10.0, 'l3_9': 8.0, 'l3_10': 0.0, 'l3_11': 5.0, 'l3_12': 6.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 0.0, 'l4_6': 5.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 9.5, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 9.0, 'e1_5': 9.0, 'e1_6': 10.0, 'e1_7': 7.0, 'e1_8': 0.0, 'e1_9': 9.0, 'e1_10': 9.0, 'e1_11': 9.0, 'e1_12': 0.0, 'e1_13': 5.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 0.0, 'l2_4': 5.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 9.5, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 8.0, 'l3_5': 10.0, 'l3_6': 8.0, 'l3_7': 9.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 10.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 10.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 9.0, 'e1_5': 0.0, 'e1_6': 0.0, 'e1_7': 0.0, 'e1_8': 0.0, 'e1_9': 0.0, 'e1_10': 0.0, 'e1_11': 0.0, 'e1_12': 0.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 10.0, 'l2_4': 9.5, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 0.0, 'l3_6': 0.0, 'l3_7': 0.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 3.0, 'l4_6': 3.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 5.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 10.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 0.0, 'e1_5': 10.0, 'e1_6': 0.0, 'e1_7': 7.0, 'e1_8': 5.0, 'e1_9': 9.0, 'e1_10': 9.0, 'e1_11': 9.0, 'e1_12': 0.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 0.0, 'l2_2': 10.0, 'l2_3': 9.5, 'l2_4': 0.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 0.0, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 0.0, 'l3_6': 0.0, 'l3_7': 0.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 5.0, 'l4_6': 3.0, 'l4_7': 0.0, 'l4_8': 3.0, 'l4_9': 10.0, 'l4_10': 7.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 9.5, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 5.0, 'e1_5': 10.0, 'e1_6': 0.0, 'e1_7': 9.0, 'e1_8': 9.0, 'e1_9': 9.0, 'e1_10': 9.0, 'e1_11': 9.0, 'e1_12': 10.0, 'e1_13': 5.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 0.0, 'l2_4': 10.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 10.0, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 6.0, 'l3_3': 10.0, 'l3_4': 0.0, 'l3_5': 0.0, 'l3_6': 0.0, 'l3_7': 0.0, 'l3_8': 0.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 0.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 0.0, 'l4_4': 7.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 9.5, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 9.0, 'e1_5': 5.0, 'e1_6': 9.0, 'e1_7': 7.0, 'e1_8': 9.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 5.0, 'e1_13': 10.0, 'e1_14': 5.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 0.0, 'l2_4': 0.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 7.0, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 7.0, 'l3_6': 10.0, 'l3_7': 6.0, 'l3_8': 3.0, 'l3_9': 10.0, 'l3_10': 10.0, 'l3_11': 10.0, 'l3_12': 10.0, 'l3_13': 10.0, 'l3_14': 10.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 10.0, 'l4_6': 5.0, 'l4_7': 10.0, 'l4_8': 10.0, 'l4_9': 10.0, 'l4_10': 10.0, 'l4_11': 10.0, 'q1_n': 1.0, 'q1_1': 0.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 9.0, 'e1_4': 9.0, 'e1_5': 9.0, 'e1_6': 10.0, 'e1_7': 9.0, 'e1_8': 9.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 10.0, 'e1_13': 10.0, 'e1_14': 5.0, 'e1_15': 10.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 9.5, 'l2_4': 9.5, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 9.5, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 8.0, 'l3_6': 10.0, 'l3_7': 8.0, 'l3_8': 10.0, 'l3_9': 10.0, 'l3_10': 7.0, 'l3_11': 5.0, 'l3_12': 0.0, 'l3_13': 0.0, 'l3_14': 0.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 10.0, 'l4_5': 5.0, 'l4_6': 6.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 10.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 9.0, 'e1_5': 8.0, 'e1_6': 9.0, 'e1_7': 7.0, 'e1_8': 9.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 10.0, 'e1_13': 0.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 5.0, 'l2_4': 9.5, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 5.0, 'l3_2': 9.0, 'l3_3': 9.0, 'l3_4': 10.0, 'l3_5': 7.0, 'l3_6': 10.0, 'l3_7': 10.0, 'l3_8': 10.0, 'l3_9': 10.0, 'l3_10': 7.0, 'l3_11': 10.0, 'l3_12': 3.0, 'l3_13': 5.0, 'l3_14': 10.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 0.0, 'l4_3': 0.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 10.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 9.0, 'e1_4': 8.0, 'e1_5': 7.0, 'e1_6': 10.0, 'e1_7': 0.0, 'e1_8': 9.0, 'e1_9': 10.0, 'e1_10': 9.0, 'e1_11': 10.0, 'e1_12': 9.0, 'e1_13': 5.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 9.5, 'l2_4': 0.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 0.0, 'l3_n': 14.0, 'l3_1': 9.5, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 10.0, 'l3_6': 10.0, 'l3_7': 10.0, 'l3_8': 10.0, 'l3_9': 0.0, 'l3_10': 0.0, 'l3_11': 10.0, 'l3_12': 5.0, 'l3_13': 10.0, 'l3_14': 10.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 5.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 0.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 0.0, 'e1_5': 8.0, 'e1_6': 9.0, 'e1_7': 7.0, 'e1_8': 9.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 10.0, 'e1_13': 10.0, 'e1_14': 0.0, 'e1_15': 0.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 9.5, 'l2_4': 9.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.5, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 10.0, 'l3_6': 10.0, 'l3_7': 9.0, 'l3_8': 10.0, 'l3_9': 3.0, 'l3_10': 0.0, 'l3_11': 3.0, 'l3_12': 3.0, 'l3_13': 5.0, 'l3_14': 2.0, 'l4_n': 11.0, 'l4_1': 0.0, 'l4_2': 0.0, 'l4_3': 0.0, 'l4_4': 0.0, 'l4_5': 0.0, 'l4_6': 0.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 0.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 0.0, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 5.0, 'e1_5': 5.0, 'e1_6': 0.0, 'e1_7': 0.0, 'e1_8': 10.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 0.0, 'e1_13': 10.0, 'e1_14': 5.0, 'e1_15': 10.0}\n", + "{'l1_n': 1.0, 'l1_1': 10.0, '12_n': 7.0, 'l2_1': 10.0, 'l2_2': 10.0, 'l2_3': 3.0, 'l2_4': 7.0, 'l2_5': 10.0, 'l2_6': 10.0, 'l2_7': 9.0, 'l3_n': 14.0, 'l3_1': 10.0, 'l3_2': 10.0, 'l3_3': 10.0, 'l3_4': 10.0, 'l3_5': 0.0, 'l3_6': 10.0, 'l3_7': 9.0, 'l3_8': 10.0, 'l3_9': 7.0, 'l3_10': 7.0, 'l3_11': 3.0, 'l3_12': 7.0, 'l3_13': 5.0, 'l3_14': 8.0, 'l4_n': 11.0, 'l4_1': 10.0, 'l4_2': 10.0, 'l4_3': 10.0, 'l4_4': 8.0, 'l4_5': 5.0, 'l4_6': 3.0, 'l4_7': 0.0, 'l4_8': 0.0, 'l4_9': 7.0, 'l4_10': 0.0, 'l4_11': 0.0, 'q1_n': 1.0, 'q1_1': 9.5, 'e1_n': 15.0, 'e1_1': 9.0, 'e1_2': 9.0, 'e1_3': 10.0, 'e1_4': 10.0, 'e1_5': 7.0, 'e1_6': 10.0, 'e1_7': 10.0, 'e1_8': 10.0, 'e1_9': 10.0, 'e1_10': 10.0, 'e1_11': 10.0, 'e1_12': 10.0, 'e1_13': 9.0, 'e1_14': 8.0, 'e1_15': 2.0}\n", + "\n", + "As unsupported: \n", + " None\n", + "\n", + "Defaults:\n", + " ['l1_n', 'l1_1', '12_n', 'l2_1', 'l2_2', 'l2_3', 'l2_4', 'l2_5', 'l2_6', 'l2_7', 'l3_n', 'l3_1', 'l3_2', 'l3_3', 'l3_4', 'l3_5', 'l3_6', 'l3_7', 'l3_8', 'l3_9', 'l3_10', 'l3_11', 'l3_12', 'l3_13', 'l3_14', 'l4_n', 'l4_1', 'l4_2', 'l4_3', 'l4_4', 'l4_5', 'l4_6', 'l4_7', 'l4_8', 'l4_9', 'l4_10', 'l4_11', 'q1_n', 'q1_1', 'e1_n', 'e1_1', 'e1_2', 'e1_3', 'e1_4', 'e1_5', 'e1_6', 'e1_7', 'e1_8', 'e1_9', 'e1_10', 'e1_11', 'e1_12', 'e1_13', 'e1_14', 'e1_15'] [1.0, 10.0, 7.0, 0.0, 10.0, 10.0, 8.0, 10.0, 10.0, 10.0, 14.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 0.0, 9.0, 8.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 14.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 14.0, 9.0, 10.0, 10.0, 10.0, 7.0, 10.0, 3.0, 6.0, 3.0, 3.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 5.0, 15.0, 5.0, 5.0, 5.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 3.0, 9.5, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 8.0, 5.0, 10.0, 5.0, 10.0, 3.0, 0.0, 10.0, 3.0, 10.0, 8.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 10.0, 5.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 7.0, 9.0, 0.0, 0.0, 10.0, 10.0, 9.0, 5.0, 10.0, 8.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 9.5, 0.0, 0.0, 10.0, 0.0, 10.0, 5.0, 10.0, 7.0, 0.0, 10.0, 6.0, 10.0, 0.0, 11.0, 10.0, 10.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 0.0, 0.0, 0.0, 0.0, 5.0, 0.0, 7.0, 0.0, 3.0, 3.0, 3.0, 0.0, 3.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 10.0, 9.5, 10.0, 10.0, 9.5, 14.0, 5.0, 9.5, 9.5, 8.0, 10.0, 10.0, 8.0, 10.0, 8.0, 0.0, 5.0, 6.0, 0.0, 0.0, 11.0, 0.0, 10.0, 10.0, 10.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 9.0, 9.0, 10.0, 7.0, 0.0, 9.0, 9.0, 9.0, 0.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 5.0, 10.0, 10.0, 9.5, 14.0, 9.5, 10.0, 10.0, 8.0, 10.0, 8.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 0.0, 10.0, 10.0, 0.0, 0.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 10.0, 9.5, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 3.0, 3.0, 0.0, 0.0, 5.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 0.0, 10.0, 0.0, 7.0, 5.0, 9.0, 9.0, 9.0, 0.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 0.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 5.0, 3.0, 0.0, 3.0, 10.0, 7.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 5.0, 10.0, 0.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 10.0, 10.0, 10.0, 10.0, 14.0, 10.0, 6.0, 10.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 0.0, 7.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 9.0, 5.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 5.0, 10.0, 5.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 0.0, 0.0, 10.0, 10.0, 7.0, 14.0, 10.0, 10.0, 10.0, 10.0, 7.0, 10.0, 6.0, 3.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 11.0, 10.0, 10.0, 10.0, 10.0, 10.0, 5.0, 10.0, 10.0, 10.0, 10.0, 10.0, 1.0, 0.0, 15.0, 9.0, 9.0, 9.0, 9.0, 9.0, 10.0, 9.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 5.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 9.5, 10.0, 10.0, 9.5, 14.0, 9.5, 10.0, 10.0, 10.0, 8.0, 10.0, 8.0, 10.0, 10.0, 7.0, 5.0, 0.0, 0.0, 0.0, 11.0, 10.0, 10.0, 10.0, 10.0, 5.0, 6.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 10.0, 9.0, 8.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 5.0, 9.5, 10.0, 10.0, 9.5, 14.0, 5.0, 9.0, 9.0, 10.0, 7.0, 10.0, 10.0, 10.0, 10.0, 7.0, 10.0, 3.0, 5.0, 10.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 10.0, 15.0, 9.0, 9.0, 9.0, 8.0, 7.0, 10.0, 0.0, 9.0, 10.0, 9.0, 10.0, 9.0, 5.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 0.0, 10.0, 10.0, 0.0, 14.0, 9.5, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0, 10.0, 5.0, 10.0, 10.0, 11.0, 0.0, 10.0, 10.0, 0.0, 0.0, 5.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 9.0, 9.0, 10.0, 0.0, 8.0, 9.0, 7.0, 9.0, 10.0, 10.0, 10.0, 10.0, 10.0, 0.0, 0.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 9.5, 9.0, 10.0, 10.0, 9.5, 14.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 10.0, 3.0, 0.0, 3.0, 3.0, 5.0, 2.0, 11.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 15.0, 9.0, 9.0, 10.0, 5.0, 5.0, 0.0, 0.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 5.0, 10.0]\n", + "[1.0, 10.0, 7.0, 10.0, 10.0, 3.0, 7.0, 10.0, 10.0, 9.0, 14.0, 10.0, 10.0, 10.0, 10.0, 0.0, 10.0, 9.0, 10.0, 7.0, 7.0, 3.0, 7.0, 5.0, 8.0, 11.0, 10.0, 10.0, 10.0, 8.0, 5.0, 3.0, 0.0, 0.0, 7.0, 0.0, 0.0, 1.0, 9.5, 15.0, 9.0, 9.0, 10.0, 10.0, 7.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 9.0, 8.0, 2.0]\n" + ] + } + ], + "source": [ + "#Lists of Lists\n", + "dataListOfLists, dataKeys = csv_reader(\"Data1401-Grades.txt\")\n", + "print(\"\\nAs a List of Lists: \\nKeys: \\n \", dataKeys,'\\nData:\\n', '\\n'.join(map(str, dataListOfLists)))\n", + "\n", + "#Dict of Lists\n", + "dataAsDictOfLists = csv_reader(\"Data1401-Grades.txt\",\"DictOfLists\")\n", + "print(\"\\nAs a Dict of Lists:\")\n", + "for key, value in dataAsDictOfLists.items():\n", + " print(key, ' : ', value)\n", + " \n", + " \n", + "#Lists of Dicts\n", + "dataListOfDicts = csv_reader(\"Data1401-Grades.txt\",\"ListOfDicts\")\n", + "print(\"\\nAs a List of Dicts:\")\n", + "for idx in range(len(dataListOfDicts)):\n", + " print(dataListOfDicts[idx])\n", + " \n", + "#Unsupported structure format\n", + "badData = csv_reader(\"Data1401-Grades.txt\",\"Unsupported\")\n", + "print(\"\\nAs unsupported: \\n\", badData)\n", + "\n", + "\n", + "#Default parameters\n", + "dataAsListofLists, dataKeys = csv_reader(\"Data1401-Grades.txt\")\n", + "print(\"\\nDefaults:\\n\", dataKeys, '\\n'.join(map(str, dataAsListofLists)))" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "6j5vA9-q04bo" + }, + "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": 433, + "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": [ + "#Read in data file and create a gradebook\n", + "class_data = csv_reader(\"Data1401-Grades.txt\",\"ListOfDicts\")\n", + "\n", + "a_grade_book=grade_book(\"Data 1401\")\n", + "\n", + "for student_i in range(len(class_data)):\n", + " #instantiate a student obj w/ an id\n", + " a_student_0=student(\"Student\",str(student_i),student_i)\n", + "\n", + " #use key value pairs of class_data to add grades to the student then add student to gradebook\n", + " for key, grade_value in class_data[student_i].items():\n", + " a_student_0.add_grade(grade(key,value=grade_value))\n", + "\n", + " a_grade_book.add_student(a_student_0)\n", + "\n", + "a_grade_book.print_data()\n", + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "EDEC17cs04br" + }, + "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": 434, + "metadata": {}, + "outputs": [], + "source": [ + "#updated\n", + "class grade_summer(calculator):\n", + " def __init__(self,prefix,n=None):\n", + " self.__prefix=prefix\n", + " self.__n=n\n", + " calculator.__init__(self,\"Sum Grades\")\n", + " \n", + " def apply(self,a_grade_book,**kwargs):\n", + " first=True\n", + " \n", + " #print('prefix = ', self.__prefix, ' n= ', str(self.__n))\n", + "\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " if first:\n", + " first=False \n", + " if self.__n:\n", + " labels=[self.__prefix+str(x) for x in range(1,self.__n)]\n", + " else:\n", + " labels=list()\n", + " for i in range(1,1000):\n", + " label=self.__prefix+str(i)\n", + " try:\n", + " a_grade=a_student[label]\n", + " labels.append(label)\n", + " except:\n", + " break \n", + "\n", + " grade_sum=0.\n", + " for label in labels:\n", + " grade_sum+=a_student[label].value()\n", + "\n", + " a_student.add_grade(grade(self.__prefix+\"sum\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 435, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Data l2_sum: 58.0 \n", + "Student 1 Student Data l2_sum: 0 \n", + "Student 2 Student Data l2_sum: 0 \n", + "Student 3 Student Data l2_sum: 62.0 \n", + "Student 4 Student Data l2_sum: 49.5 \n", + "Student 5 Student Data l2_sum: 69.0 \n", + "Student 6 Student Data l2_sum: 54.5 \n", + "Student 7 Student Data l2_sum: 69.0 \n", + "Student 8 Student Data l2_sum: 39.5 \n", + "Student 9 Student Data l2_sum: 60.0 \n", + "Student 10 Student Data l2_sum: 47.0 \n", + "Student 11 Student Data l2_sum: 68.5 \n", + "Student 12 Student Data l2_sum: 64.0 \n", + "Student 13 Student Data l2_sum: 49.5 \n", + "Student 14 Student Data l2_sum: 68.0 \n", + "Student 15 Student Data l2_sum: 59.0 \n" + ] + } + ], + "source": [ + "#checking that grade summerization calc works (all exercises from one lab)\n", + "a_grade_book.apply_calculator(grade_summer(\"l2_\"),overwrite=True)\n", + "a_grade_book.print_grades(\"l2_sum\")" + ] + }, + { + "cell_type": "code", + "execution_count": 436, + "metadata": {}, + "outputs": [], + "source": [ + "#summing grades for all labs, quizzes, exams of each student\n", + "a_grade_book.apply_calculator(grade_summer(\"l1_\"),overwrite=True)\n", + "a_grade_book.apply_calculator(grade_summer(\"l2_\"),overwrite=True)\n", + "a_grade_book.apply_calculator(grade_summer(\"l3_\"),overwrite=True)\n", + "a_grade_book.apply_calculator(grade_summer(\"l4_\"),overwrite=True)\n", + "\n", + "a_grade_book.apply_calculator(grade_summer(\"e1_\"),overwrite=True)\n", + "\n", + "a_grade_book.apply_calculator(grade_summer(\"q1_\"),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 437, + "metadata": {}, + "outputs": [], + "source": [ + "# uncurved calculator against the summed scores\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"l1_sum\",max_grade=10))\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"l2_sum\",max_grade=70))\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"l3_sum\",max_grade=140))\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"l4_sum\",max_grade=110))\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"q1_sum\",max_grade=10))\n", + "a_grade_book.apply_calculator(uncurved_letter_grade_percent(\"e1_sum\",max_grade=150))" + ] + }, + { + "cell_type": "code", + "execution_count": 438, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Data l1_sum: 10.0 \n", + "Student 1 Student Data l1_sum: 10.0 \n", + "Student 2 Student Data l1_sum: 10.0 \n", + "Student 3 Student Data l1_sum: 10.0 \n", + "Student 4 Student Data l1_sum: 10.0 \n", + "Student 5 Student Data l1_sum: 10.0 \n", + "Student 6 Student Data l1_sum: 10.0 \n", + "Student 7 Student Data l1_sum: 10.0 \n", + "Student 8 Student Data l1_sum: 10.0 \n", + "Student 9 Student Data l1_sum: 10.0 \n", + "Student 10 Student Data l1_sum: 10.0 \n", + "Student 11 Student Data l1_sum: 10.0 \n", + "Student 12 Student Data l1_sum: 10.0 \n", + "Student 13 Student Data l1_sum: 10.0 \n", + "Student 14 Student Data l1_sum: 10.0 \n", + "Student 15 Student Data l1_sum: 10.0 \n", + "------------------\n", + "Student 0 Student Data l2_sum: 58.0 \n", + "Student 1 Student Data l2_sum: 0 \n", + "Student 2 Student Data l2_sum: 0 \n", + "Student 3 Student Data l2_sum: 62.0 \n", + "Student 4 Student Data l2_sum: 49.5 \n", + "Student 5 Student Data l2_sum: 69.0 \n", + "Student 6 Student Data l2_sum: 54.5 \n", + "Student 7 Student Data l2_sum: 69.0 \n", + "Student 8 Student Data l2_sum: 39.5 \n", + "Student 9 Student Data l2_sum: 60.0 \n", + "Student 10 Student Data l2_sum: 47.0 \n", + "Student 11 Student Data l2_sum: 68.5 \n", + "Student 12 Student Data l2_sum: 64.0 \n", + "Student 13 Student Data l2_sum: 49.5 \n", + "Student 14 Student Data l2_sum: 68.0 \n", + "Student 15 Student Data l2_sum: 59.0 \n", + "------------------\n", + "Student 0 Student Data l3_sum: 9.0 \n", + "Student 1 Student Data l3_sum: 0 \n", + "Student 2 Student Data l3_sum: 71.0 \n", + "Student 3 Student Data l3_sum: 102.0 \n", + "Student 4 Student Data l3_sum: 77.5 \n", + "Student 5 Student Data l3_sum: 89.0 \n", + "Student 6 Student Data l3_sum: 64.5 \n", + "Student 7 Student Data l3_sum: 40.0 \n", + "Student 8 Student Data l3_sum: 40.0 \n", + "Student 9 Student Data l3_sum: 26.0 \n", + "Student 10 Student Data l3_sum: 126.0 \n", + "Student 11 Student Data l3_sum: 97.5 \n", + "Student 12 Student Data l3_sum: 115.0 \n", + "Student 13 Student Data l3_sum: 114.5 \n", + "Student 14 Student Data l3_sum: 95.0 \n", + "Student 15 Student Data l3_sum: 106.0 \n", + "------------------\n", + "Student 0 Student Data l4_sum: 0 \n", + "Student 1 Student Data l4_sum: 0 \n", + "Student 2 Student Data l4_sum: 0 \n", + "Student 3 Student Data l4_sum: 75.0 \n", + "Student 4 Student Data l4_sum: 26.0 \n", + "Student 5 Student Data l4_sum: 35.0 \n", + "Student 6 Student Data l4_sum: 30.0 \n", + "Student 7 Student Data l4_sum: 51.0 \n", + "Student 8 Student Data l4_sum: 68.0 \n", + "Student 9 Student Data l4_sum: 27.0 \n", + "Student 10 Student Data l4_sum: 105.0 \n", + "Student 11 Student Data l4_sum: 51.0 \n", + "Student 12 Student Data l4_sum: 0 \n", + "Student 13 Student Data l4_sum: 25.0 \n", + "Student 14 Student Data l4_sum: 0 \n", + "Student 15 Student Data l4_sum: 53.0 \n", + "------------------\n", + "Student 0 Student Data q1_sum: 9.5 \n", + "Student 1 Student Data q1_sum: 0 \n", + "Student 2 Student Data q1_sum: 5.0 \n", + "Student 3 Student Data q1_sum: 10.0 \n", + "Student 4 Student Data q1_sum: 0 \n", + "Student 5 Student Data q1_sum: 9.5 \n", + "Student 6 Student Data q1_sum: 10.0 \n", + "Student 7 Student Data q1_sum: 10.0 \n", + "Student 8 Student Data q1_sum: 9.5 \n", + "Student 9 Student Data q1_sum: 9.5 \n", + "Student 10 Student Data q1_sum: 0 \n", + "Student 11 Student Data q1_sum: 10.0 \n", + "Student 12 Student Data q1_sum: 10.0 \n", + "Student 13 Student Data q1_sum: 0 \n", + "Student 14 Student Data q1_sum: 0 \n", + "Student 15 Student Data q1_sum: 9.5 \n", + "------------------\n", + "Student 0 Student Data e1_sum: 35.0 \n", + "Student 1 Student Data e1_sum: 0 \n", + "Student 2 Student Data e1_sum: 20.0 \n", + "Student 3 Student Data e1_sum: 115.0 \n", + "Student 4 Student Data e1_sum: 24.0 \n", + "Student 5 Student Data e1_sum: 95.0 \n", + "Student 6 Student Data e1_sum: 37.0 \n", + "Student 7 Student Data e1_sum: 77.0 \n", + "Student 8 Student Data e1_sum: 103.0 \n", + "Student 9 Student Data e1_sum: 117.0 \n", + "Student 10 Student Data e1_sum: 138.0 \n", + "Student 11 Student Data e1_sum: 110.0 \n", + "Student 12 Student Data e1_sum: 104.0 \n", + "Student 13 Student Data e1_sum: 111.0 \n", + "Student 14 Student Data e1_sum: 103.0 \n", + "Student 15 Student Data e1_sum: 134.0 \n" + ] + } + ], + "source": [ + "a_grade_book.print_grades(\"l1_sum\")\n", + "print(\"------------------\")\n", + "a_grade_book.print_grades(\"l2_sum\")\n", + "print(\"------------------\")\n", + "a_grade_book.print_grades(\"l3_sum\")\n", + "print(\"------------------\")\n", + "a_grade_book.print_grades(\"l4_sum\")\n", + "print(\"------------------\")\n", + "a_grade_book.print_grades(\"q1_sum\")\n", + "print(\"------------------\")\n", + "a_grade_book.print_grades(\"e1_sum\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "ypmLSUIg04bt" + }, + "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": 439, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "P83j_0j904bu" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "l1_sum Mean: 10.0\n", + "l1_sum STD: 0.0\n", + "l2_sum Mean: 51.09\n", + "l2_sum STD: 21.06\n", + "l3_sum Mean: 73.31\n", + "l3_sum STD: 38.3\n", + "l4_sum Mean: 34.12\n", + "l4_sum STD: 30.42\n", + "e1_sum Mean: 82.69\n", + "e1_sum STD: 42.94\n", + "q1_sum Mean: 6.41\n", + "q1_sum STD: 4.47\n" + ] + } + ], + "source": [ + "# Your solution here\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"l1_sum\")\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"l2_sum\")\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"l3_sum\")\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"l4_sum\")\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"e1_sum\")\n", + "a_grade_book.apply_calculator(mean_std_calculator(), grade_name=\"q1_sum\")\n", + "\n", + "a_grade_book.print_stats()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "pmvox8hk04bw" + }, + "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": 440, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "HBDyHAf604bw" + }, + "outputs": [], + "source": [ + "class curved_letter_grade(calculator):\n", + " __grades_definition=[ (.97,\"A+\"),\n", + " (.93,\"A\"),\n", + " (.9,\"A-\"),\n", + " (.87,\"B+\"),\n", + " (.83,\"B\"),\n", + " (.8,\"B-\"),\n", + " (.77,\"C+\"),\n", + " (.73,\"C\"),\n", + " (.7,\"C-\"),\n", + " (.67,\"C+\"),\n", + " (.63,\"C\"),\n", + " (.6,\"C-\"),\n", + " (.57,\"F+\"),\n", + " (.53,\"F\"),\n", + " (0.,\"F-\")]\n", + " __max_grade=100.\n", + " __grade_name=str()\n", + " \n", + " def __init__(self,grade_name,mean,std,max_grade=100.):\n", + " self.__max_grade=max_grade\n", + " self.__mean=mean\n", + " self.__std=std\n", + " self.__grade_name=grade_name\n", + " calculator.__init__(self,\n", + " \"Curved Percent Based Grade Calculator \"+self.__grade_name+ \\\n", + " \" Mean=\"+str(self.__mean)+\\\n", + " \" STD=\"+str(self.__std)+\\\n", + " \" Max=\"+str(self.__max_grade))\n", + " \n", + "\n", + " def apply(self,a_grade,grade_name=None, **kwargs):\n", + " if grade_name:\n", + " pass\n", + " else:\n", + " grade_name=self.__grade_name\n", + " \n", + " #print('maxgrade:', self.__max_grade,'mean: ',self.__mean, 'std: ',self.__std)\n", + " #iterate through the students and grab the selected grades\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", + " shift_to_zero=percent-(self.__mean/self.__max_grade)\n", + " if (self.__std/self.__max_grade)!=0:\n", + " scale_std=0.1*shift_to_zero/(self.__std/self.__max_grade)\n", + " scaled_percent=scale_std+0.8\n", + " else:\n", + " #handle case if std was 0 leading to Nan problems\n", + " scaled_percent=percent\n", + " \n", + " #print(a_student.id_number(),'gradename=',grade_name,'value=',a_grade.value(),\n", + " #'%:',round(percent,2), '<0:',round(shift_to_zero,2),'scaleSTD:',scale_std,'scale%:',scaled_percent)\n", + " \n", + " for i,v in enumerate(self.__grades_definition):\n", + " if scaled_percent>=v[0]:\n", + " break\n", + " \n", + " \n", + " new_name = grade_name.replace(\"sum\",\"Curved Letter\") \n", + " a_student.add_grade(grade(new_name,value=self.__grades_definition[i][1]))\n", + " " + ] + }, + { + "cell_type": "code", + "execution_count": 441, + "metadata": {}, + "outputs": [], + "source": [ + "a_grade_book.apply_calculator(curved_letter_grade(\"l1_sum\",a_grade_book[\"l1_sum Mean\"],a_grade_book[\"l1_sum STD\"],max_grade=10))\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l2_sum\",a_grade_book[\"l2_sum Mean\"],a_grade_book[\"l2_sum STD\"],max_grade=140))\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l3_sum\",a_grade_book[\"l3_sum Mean\"],a_grade_book[\"l3_sum STD\"],max_grade=110))\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"l4_sum\",a_grade_book[\"l4_sum Mean\"],a_grade_book[\"l4_sum STD\"],max_grade=10))\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"q1_sum\",a_grade_book[\"q1_sum Mean\"],a_grade_book[\"q1_sum STD\"],max_grade=150))\n", + "a_grade_book.apply_calculator(curved_letter_grade(\"e1_sum\",a_grade_book[\"e1_sum Mean\"],a_grade_book[\"e1_sum STD\"],max_grade=100))" + ] + }, + { + "cell_type": "code", + "execution_count": 442, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Data " + ] + }, + { + "ename": "KeyError", + "evalue": "'l1_Curved Letter'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mKeyError\u001b[0m Traceback (most recent call last)", + "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0ma_grade_book\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprint_grades\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"l1_Curved Letter\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"---------------------\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 3\u001b[0m \u001b[0ma_grade_book\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprint_grades\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"l2_Curved Letter\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"---------------------\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0ma_grade_book\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mprint_grades\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"l3_Curved Letter\"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36mprint_grades\u001b[0;34m(self, grade_name)\u001b[0m\n\u001b[1;32m 64\u001b[0m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0ma_student\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mend\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\" \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 65\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0ma_grade_name\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mgrade_names\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 66\u001b[0;31m \u001b[0mprint\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0ma_student\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0ma_grade_name\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mend\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m\" \"\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 67\u001b[0m \u001b[0mprint\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 68\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;32m\u001b[0m in \u001b[0;36m__getitem__\u001b[0;34m(self, key)\u001b[0m\n\u001b[1;32m 69\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 70\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0m__getitem__\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 71\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__grades\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 72\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n", + "\u001b[0;31mKeyError\u001b[0m: 'l1_Curved Letter'" + ] + } + ], + "source": [ + "a_grade_book.print_grades(\"l1_Curved Letter\")\n", + "print(\"---------------------\")\n", + "a_grade_book.print_grades(\"l2_Curved Letter\")\n", + "print(\"---------------------\")\n", + "a_grade_book.print_grades(\"l3_Curved Letter\")\n", + "print(\"---------------------\")\n", + "a_grade_book.print_grades(\"l4_Curved Letter\")\n", + "print(\"---------------------\")\n", + "a_grade_book.print_grades(\"q1_Curved Letter\")\n", + "print(\"---------------------\")\n", + "a_grade_book.print_grades(\"e1_Curved Letter\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "TZceJaJ404bz" + }, + "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": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 443, + "metadata": {}, + "outputs": [], + "source": [ + "class grade_final(calculator):\n", + " def __init__(self,prefix,drop=0):\n", + " self.__prefix=prefix\n", + " self.__drop=drop\n", + " calculator.__init__(self,\"Final Grades\")\n", + " \n", + " def apply(self,a_grade_book,**kwargs):\n", + " # for each student in the grade book\n", + "\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " labels=list()\n", + " for i in range(1,1000):\n", + " label=self.__prefix+str(i)+\"_sum\" \n", + " try:\n", + " a_grade=a_student[label]\n", + " labels.append(label)\n", + " except:\n", + " break \n", + "\n", + " grade_list=list()\n", + " for label in labels:\n", + " grade_list.append(a_student[label].value())\n", + "\n", + " # drop lowest grades defined by self.__drop but only if the number of grades is bigger than the drop number\n", + " if (len(grade_list)>self.__drop):\n", + " for x in range(self.__drop):\n", + " grade_list.remove(min(grade_list))\n", + " \n", + " grade_sum=0\n", + " for iterG in grade_list:\n", + " grade_sum+=iterG\n", + "\n", + " a_student.add_grade(grade(self.__prefix+\"_final\",value=grade_sum),**kwargs)" + ] + }, + { + "cell_type": "code", + "execution_count": 444, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Data l_final: 77.0 \n", + "Student 1 Student Data l_final: 10.0 \n", + "Student 2 Student Data l_final: 81.0 \n", + "Student 3 Student Data l_final: 249.0 \n", + "Student 4 Student Data l_final: 163.0 \n", + "Student 5 Student Data l_final: 203.0 \n", + "Student 6 Student Data l_final: 159.0 \n", + "Student 7 Student Data l_final: 170.0 \n", + "Student 8 Student Data l_final: 157.5 \n", + "Student 9 Student Data l_final: 123.0 \n", + "Student 10 Student Data l_final: 288.0 \n", + "Student 11 Student Data l_final: 227.0 \n", + "Student 12 Student Data l_final: 189.0 \n", + "Student 13 Student Data l_final: 199.0 \n", + "Student 14 Student Data l_final: 173.0 \n", + "Student 15 Student Data l_final: 228.0 \n" + ] + } + ], + "source": [ + "# Generate the final lab grades, w/ out dropping for comparison\n", + "a_grade_book.apply_calculator(grade_final(\"l\"),overwrite=True)\n", + "a_grade_book.print_grades(\"l_final\")" + ] + }, + { + "cell_type": "code", + "execution_count": 445, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student 0 Student Data l_final: 77.0 \n", + "Student 1 Student Data l_final: 10.0 \n", + "Student 2 Student Data l_final: 81.0 \n", + "Student 3 Student Data l_final: 239.0 \n", + "Student 4 Student Data l_final: 153.0 \n", + "Student 5 Student Data l_final: 193.0 \n", + "Student 6 Student Data l_final: 149.0 \n", + "Student 7 Student Data l_final: 160.0 \n", + "Student 8 Student Data l_final: 147.5 \n", + "Student 9 Student Data l_final: 113.0 \n", + "Student 10 Student Data l_final: 278.0 \n", + "Student 11 Student Data l_final: 217.0 \n", + "Student 12 Student Data l_final: 189.0 \n", + "Student 13 Student Data l_final: 189.0 \n", + "Student 14 Student Data l_final: 173.0 \n", + "Student 15 Student Data l_final: 218.0 \n" + ] + } + ], + "source": [ + "# Generate the final lab grades, dropping the lowest\n", + "a_grade_book.apply_calculator(grade_final(\"l\",drop=1),overwrite=True)\n", + "a_grade_book.print_grades(\"l_final\")" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "BJu4j4pI04b1" + }, + "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": 446, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "5gCRRYOX04b2" + }, + "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": 447, + "metadata": {}, + "outputs": [], + "source": [ + "class weighted_letter_grade(calculator):\n", + " __grades_definition=[ {\"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,\n", + " \"F\":0,\n", + " \"F-\":0}\n", + " ]\n", + "\n", + " def __init__(self,grade_name):\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", + " \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", + " #iterate through the students and grab the selected grades\n", + " for k,a_student in a_grade_book.get_students().items():\n", + " # get the grade object for the student\n", + " a_grade=a_student[grade_name]\n", + "\n", + "\n", + " if not a_grade.numerical():\n", + " print (self.name()+ \" Error: Did not get a numerical grade as input.\" + str(a_grade))\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", + " #print('add Letter: '+ grade_name+\" Letter\" + self.__grades_definition[i][1] )\n", + "\n", + " a_student.add_grade(grade(grade_name+\" Uncurved Letter\",value=self.__grades_definition[i][1]),overwrite=True)" + ] + }, + { + "cell_type": "code", + "execution_count": 448, + "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", + "l2_sum: 58.0\n", + "l1_sum: 10.0\n", + "l3_sum: 9.0\n", + "l4_sum: 0\n", + "e1_sum: 35.0\n", + "q1_sum: 9.5\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: B-\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A\n", + "e1_Uncurved Letter: F-\n", + "l_final: 77.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", + "l2_sum: 0\n", + "l1_sum: 10.0\n", + "l3_sum: 0\n", + "l4_sum: 0\n", + "e1_sum: 0\n", + "q1_sum: 0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: F-\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: F-\n", + "l_final: 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", + "l2_sum: 0\n", + "l1_sum: 10.0\n", + "l3_sum: 71.0\n", + "l4_sum: 0\n", + "e1_sum: 20.0\n", + "q1_sum: 5.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: F-\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: F-\n", + "l_final: 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", + "l2_sum: 62.0\n", + "l1_sum: 10.0\n", + "l3_sum: 102.0\n", + "l4_sum: 75.0\n", + "e1_sum: 115.0\n", + "q1_sum: 10.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: B+\n", + "l3_Uncurved Letter: C-\n", + "l4_Uncurved Letter: C+\n", + "q1_Uncurved Letter: A+\n", + "e1_Uncurved Letter: C\n", + "l_final: 239.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", + "l2_sum: 49.5\n", + "l1_sum: 10.0\n", + "l3_sum: 77.5\n", + "l4_sum: 26.0\n", + "e1_sum: 24.0\n", + "q1_sum: 0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: C-\n", + "l3_Uncurved Letter: F\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: F-\n", + "l_final: 153.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", + "l2_sum: 69.0\n", + "l1_sum: 10.0\n", + "l3_sum: 89.0\n", + "l4_sum: 35.0\n", + "e1_sum: 95.0\n", + "q1_sum: 9.5\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: A+\n", + "l3_Uncurved Letter: C\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A\n", + "e1_Uncurved Letter: C\n", + "l_final: 193.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", + "l2_sum: 54.5\n", + "l1_sum: 10.0\n", + "l3_sum: 64.5\n", + "l4_sum: 30.0\n", + "e1_sum: 37.0\n", + "q1_sum: 10.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: C+\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A+\n", + "e1_Uncurved Letter: F-\n", + "l_final: 149.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", + "l2_sum: 69.0\n", + "l1_sum: 10.0\n", + "l3_sum: 40.0\n", + "l4_sum: 51.0\n", + "e1_sum: 77.0\n", + "q1_sum: 10.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: A+\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A+\n", + "e1_Uncurved Letter: F-\n", + "l_final: 160.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", + "l2_sum: 39.5\n", + "l1_sum: 10.0\n", + "l3_sum: 40.0\n", + "l4_sum: 68.0\n", + "e1_sum: 103.0\n", + "q1_sum: 9.5\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: F\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: C-\n", + "q1_Uncurved Letter: A\n", + "e1_Uncurved Letter: C+\n", + "l_final: 147.5\n", + "_______________________________________\n", + "9 Student 9 Student Data\n", + "l1_n: 1.0\n", + "l1_1: 10.0\n", + "12_n: 7.0\n", + "l2_1: 10.0\n", + "l2_2: 10.0\n", + "l2_3: 0\n", + "l2_4: 10.0\n", + "l2_5: 10.0\n", + "l2_6: 10.0\n", + "l2_7: 10.0\n", + "l3_n: 14.0\n", + "l3_1: 10.0\n", + "l3_2: 6.0\n", + "l3_3: 10.0\n", + "l3_4: 0\n", + "l3_5: 0\n", + "l3_6: 0\n", + "l3_7: 0\n", + "l3_8: 0\n", + "l3_9: 0\n", + "l3_10: 0\n", + "l3_11: 0\n", + "l3_12: 0\n", + "l3_13: 0\n", + "l3_14: 0\n", + "l4_n: 11.0\n", + "l4_1: 10.0\n", + "l4_2: 10.0\n", + "l4_3: 0\n", + "l4_4: 7.0\n", + "l4_5: 0\n", + "l4_6: 0\n", + "l4_7: 0\n", + "l4_8: 0\n", + "l4_9: 0\n", + "l4_10: 0\n", + "l4_11: 0\n", + "q1_n: 1.0\n", + "q1_1: 9.5\n", + "e1_n: 15.0\n", + "e1_1: 9.0\n", + "e1_2: 9.0\n", + "e1_3: 10.0\n", + "e1_4: 9.0\n", + "e1_5: 5.0\n", + "e1_6: 9.0\n", + "e1_7: 7.0\n", + "e1_8: 9.0\n", + "e1_9: 10.0\n", + "e1_10: 10.0\n", + "e1_11: 10.0\n", + "e1_12: 5.0\n", + "e1_13: 10.0\n", + "e1_14: 5.0\n", + "e1_15: 0\n", + "l2_sum: 60.0\n", + "l1_sum: 10.0\n", + "l3_sum: 26.0\n", + "l4_sum: 27.0\n", + "e1_sum: 117.0\n", + "q1_sum: 9.5\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: B\n", + "l3_Uncurved Letter: F-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A\n", + "e1_Uncurved Letter: C+\n", + "l_final: 113.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", + "l2_sum: 47.0\n", + "l1_sum: 10.0\n", + "l3_sum: 126.0\n", + "l4_sum: 105.0\n", + "e1_sum: 138.0\n", + "q1_sum: 0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: C+\n", + "l3_Uncurved Letter: A-\n", + "l4_Uncurved Letter: A\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: A-\n", + "l_final: 278.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", + "l2_sum: 68.5\n", + "l1_sum: 10.0\n", + "l3_sum: 97.5\n", + "l4_sum: 51.0\n", + "e1_sum: 110.0\n", + "q1_sum: 10.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: A+\n", + "l3_Uncurved Letter: C+\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A+\n", + "e1_Uncurved Letter: C\n", + "l_final: 217.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", + "l2_sum: 64.0\n", + "l1_sum: 10.0\n", + "l3_sum: 115.0\n", + "l4_sum: 0\n", + "e1_sum: 104.0\n", + "q1_sum: 10.0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: A-\n", + "l3_Uncurved Letter: B-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A+\n", + "e1_Uncurved Letter: C+\n", + "l_final: 189.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", + "l2_sum: 49.5\n", + "l1_sum: 10.0\n", + "l3_sum: 114.5\n", + "l4_sum: 25.0\n", + "e1_sum: 111.0\n", + "q1_sum: 0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: C-\n", + "l3_Uncurved Letter: B-\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: C\n", + "l_final: 189.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", + "l2_sum: 68.0\n", + "l1_sum: 10.0\n", + "l3_sum: 95.0\n", + "l4_sum: 0\n", + "e1_sum: 103.0\n", + "q1_sum: 0\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: A+\n", + "l3_Uncurved Letter: C+\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: F-\n", + "e1_Uncurved Letter: C+\n", + "l_final: 173.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", + "l2_sum: 59.0\n", + "l1_sum: 10.0\n", + "l3_sum: 106.0\n", + "l4_sum: 53.0\n", + "e1_sum: 134.0\n", + "q1_sum: 9.5\n", + "l1_Uncurved Letter: A+\n", + "l2_Uncurved Letter: B\n", + "l3_Uncurved Letter: C\n", + "l4_Uncurved Letter: F-\n", + "q1_Uncurved Letter: A\n", + "e1_Uncurved Letter: B+\n", + "l1_Curved Letter: A+\n", + "l2_Curved Letter: B\n", + "l3_Curved Letter: B+\n", + "l4_Curved Letter: B\n", + "q1_Curved Letter: B\n", + "e1_Curved Letter: A-\n", + "l_final: 218.0\n", + "_______________________________________\n" + ] + } + ], + "source": [ + "a_grade_book.print_students()" + ] + }, + { + "cell_type": "markdown", + "metadata": { + "colab_type": "text", + "id": "i-kabW4b04b3" + }, + "source": [ + "Test you calculator by applying the weights from the syllabus of this course and computing everyone's grade in the course." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "colab": {}, + "colab_type": "code", + "id": "eJ55xMTa04b4" + }, + "outputs": [], + "source": [ + "# Your solution here" + ] + }, + { + "cell_type": "code", + "execution_count": 449, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Copy_of_Lab_7.ipynb Data1401-Grades.txt\r\n" + ] + } + ], + "source": [ + "!ls" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "Copy of 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.3" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}