From 2d81f00d012eaefb440f8dabe704be1dccb76519 Mon Sep 17 00:00:00 2001 From: CelesteEsquivel <60523783+CelesteEsquivel@users.noreply.github.com> Date: Fri, 11 Sep 2020 14:37:38 -0500 Subject: [PATCH 1/3] Add files via upload --- Labs/Lab-1-Solutions.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 Labs/Lab-1-Solutions.ipynb diff --git a/Labs/Lab-1-Solutions.ipynb b/Labs/Lab-1-Solutions.ipynb new file mode 100644 index 0000000..0d14e2b --- /dev/null +++ b/Labs/Lab-1-Solutions.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Copy of Lab-1.ipynb","provenance":[{"file_id":"https://github.com/UTA-DataScience/DATA1401.2020.Fall/blob/master/Labs/Lab.1/Lab.1.ipynb","timestamp":1599246842398}],"collapsed_sections":[]},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.0"}},"cells":[{"cell_type":"markdown","metadata":{"colab_type":"text","id":"O5vg8KKRq0sy"},"source":["# Lab 1\n","\n","## Python Notebooks on Google Colab\n","\n","Data 1401's Labs, Homework, and Exams will be all in form of iPython notebooks. You may already be familiar with python notebooks if you have used Jupyter before. 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). You may also choose to store your 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/UTA-DataScience/DATA1401.2020.Fall/blob/master/Labs/Lab.1/Lab.1.ipynb)\n"]},{"cell_type":"code","metadata":{"id":"q3CA8YvTi2Aw","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1599848883893,"user_tz":300,"elapsed":28929,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"7a334088-8bc2-4aad-b956-70eda3e0a1de"},"source":["from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Mounted at /content/drive\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"FVt_1hPt1dAK"},"source":["## Notebooks in Colab\n","\n","You now are presumably in Colab. Word of caution, by default, Google Colab does not save your notebooks, so if you close your session, you will loose your work.\n","\n","So first thing: from the file menu above select \"Save a copy in Drive\"."]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"x0JBL_RFrDDj"},"source":["## Storing Notebooks in Google Drive (Optional)\n","If you like, you may save your notebooks directly into Google Drive and upload directly to Git (where you will be downloading and uploading your homework). In order properly setup Git, we'll need to work more directly in your Google Drive.\n","\n","On the left sidebar, press the file icon to see a listing of files accessibile to this Notebook. Then press \"Mount Drive\" and follow the instructions to mount your Google Drive in this notebook. A new cell will be inserted into this notebook, which after you run by pressing the play button will instruct you to follow a link to log into your Google Account and enable access to your Drive in another tab. Finally you will copy a link from the new tab back into the cell in this notebook. Once you are done, press refresh under files in the left sidebar and you should have \"drive/My Drive\" appear."]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"hwJ6wJk3tiLv"},"source":["## Github\n","All the class material will be stored on github. You will also submit your homework using github. To do so, you will need a github account.\n","\n","If you do not already have a github account or wish to create a new one for this course, create one:\n","* Browse to [github.com](https://github.com).\n","* Click the green “Sign up for GitHub”\tbutton.\n","* Follow instructions for creating an account.\n","* Make sure you remember your github username and password.\n","\n","Write an email to the course Instructor titled \"Data 1401: Github account\" with your github username (not your password) as the contents.\n","\n","## Google Groups\n","\n","Class annoucements will be made via google groups. If you did not already receive an invite to the class google group, had trouble with the invite, or wish to use a different email address, write an email to the course TA titled \"Data 1401: Google Group\" with your preferred email.\n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"TjfIzdQZqvzk"},"source":["## Introduction: Unix, Git, and Jupyter\n","\n","This lab aims to introduce you to basic Unix, familiarize you with iPython notebooks and get you setup to submit your homework.\n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"C_LmOgzFqvzp"},"source":["\n","\n","### Terminal, Shell, and ssh\n","\n","\n","The terminal is a simple program that generally runs another program, taking mostly keyboard input from you, passing it to this other program, and taking the output of the program and displaying on the screen for you.\n","\n","The terminal usually runs a program called a shell. Shells present a command prompt where you can type in commands, which are then executed when you press enter. In most shells, there are some special commands which the shell will execute. Everything else you type in, the shell will assume is a name of a program you want to run and arguments you want to pass that program. So if the shell doesn't recognize something you type in, it'll try to find a program with a name that is the same as the first word you gave it. \n","\n","### Shell in Colab\n","\n","Unfortunately, google Colab does not allow you to open a terminal window. Jupyter does, so if you are running in Jupyter (which most of you will not be), you may choose to open a terminal window by returning to the jupyter file list tab and selecting new terminal from the top right.\n","\n","For Colab, we will have to do something non-ideal, but functional. There are several ways to execute shell commands from within a python notebook. For example, you can use any shell command by putting \"!\" in front of the command:\n","\n","\n","\n"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"KJ5f-WO0wcAv","colab":{"base_uri":"https://localhost:8080/","height":101},"executionInfo":{"status":"ok","timestamp":1599848915315,"user_tz":300,"elapsed":541,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"1dad08d0-05d9-4438-c6d1-9d360d374468"},"source":["!ls\n","!echo \"----------\"\n","!ls sample_data"],"execution_count":null,"outputs":[{"output_type":"stream","text":["drive sample_data\n","----------\n","anscombe.json\t\t mnist_test.csv\n","california_housing_test.csv mnist_train_small.csv\n","california_housing_train.csv README.md\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"8f-n4AXFw-dD"},"source":["Unfortunately, every time you use \"!\" a new environment is created and the state reverted to the original state. Try to understand the difference between the following two sets of commands:\n"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"99nrBYTWxZJr","colab":{"base_uri":"https://localhost:8080/","height":67},"executionInfo":{"status":"ok","timestamp":1599848920035,"user_tz":300,"elapsed":607,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"2882d3cb-8ae5-4b25-ed79-785d8a099038"},"source":["!echo \"Technique 1:\"\n","!ls\n","!cd sample_data\n","!ls"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Technique 1:\n","drive sample_data\n","drive sample_data\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"colab_type":"code","id":"2-Znf97Lxl-Z","colab":{"base_uri":"https://localhost:8080/","height":101},"executionInfo":{"status":"ok","timestamp":1599848924845,"user_tz":300,"elapsed":496,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"6ecaa71f-8e98-4878-c50b-fcadc15e68ad"},"source":["!echo \"Technique 2:\"\n","!ls ; cd sample_data ;ls"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Technique 2:\n","drive sample_data\n","anscombe.json\t\t mnist_test.csv\n","california_housing_test.csv mnist_train_small.csv\n","california_housing_train.csv README.md\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"4x9n1rAkxyYl"},"source":["Notebooks allow a bit of \"magic\" (using \"%\") to avoid some of these limitations:\n"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"vLBPTX4rx3gd","colab":{"base_uri":"https://localhost:8080/","height":118},"executionInfo":{"status":"ok","timestamp":1599848929231,"user_tz":300,"elapsed":656,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"cd7860be-e382-4c76-c45e-4d37c1861ef4"},"source":["!echo \"Technique 3:\"\n","!ls \n","%cd sample_data \n","!ls"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Technique 3:\n","drive sample_data\n","/content/sample_data\n","anscombe.json\t\t mnist_test.csv\n","california_housing_test.csv mnist_train_small.csv\n","california_housing_train.csv README.md\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"U8XpvPjcyH0w"},"source":["For our purposes, we are just going to explicitly start a new shell and interact with it in the output cell. Execute the following cell. You will be able to type and execute commands. Look around a bit using \"ls\" and \"cd. You can stop the cell from running by typing \"exit\". You may also stop the shell by pressing play/stop button."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"MIDFitLZyuZy","colab":{"base_uri":"https://localhost:8080/","height":151},"executionInfo":{"status":"ok","timestamp":1599848959183,"user_tz":300,"elapsed":7092,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"da441010-88dc-438e-aade-82f52bc8281d"},"source":["!/bin/bash --noediting"],"execution_count":null,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (102): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ls\n","\u001b[0m\u001b[01;32manscombe.json\u001b[0m mnist_test.csv\n","california_housing_test.csv mnist_train_small.csv\n","california_housing_train.csv \u001b[01;32mREADME.md\u001b[0m\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"q-4hfZBywW25"},"source":["While in this instance your shell is running in a this notebook, you can also run terminals natively on your own computer. On Linux or MacOS, you just have to run a program called terminal. In Windows you can start a \"command prompt\". \n","\n","Type in \"ls\" into the terminal above 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. \n","\n","For your reference, [Unix/Linux Command Reference](https://github.com/UTA-DataScience/VersionControlSystem/blob/master/VersionControlSystem/linuxRef.pdf) summarizes some of the common shell commands.\n","\n","A subtle point to realize here is that while the terminal is running in the browser that is running on the computer in front of you, the shell is actually running on a machine on google hardware. The shell prompt typically displays the name of the machine you are using. What you are not seeing is that there is an intermidate program between the terminal running on your computer and the shell running on google. This intermidary program is taking your input from the terminal sending it over the network to google and bringing back the responses for you terminal to display.\n","\n","A bit of extra information. If you start a terminal on your own computer, the shell runs locally. The \"ls\" command would then list contents of a directory on your computer. You can typically connect to Unix computers by evoking a shell running on that machine over the network. In this case, you would have to initiate this intermidiary program yourself. The program is called \"ssh\" (secure shell). You can \"ssh\" to another machine from your machine, by simply typing \"ssh\" followed by the machine name or IP address. Most likely you would be prompted for a password, after which you would dropped into the prompt of a shell running on the remote machine. \n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"51Eya4LBqvzs"},"source":["## Programs and Environment Variables\n","\n","You have a listing of your current directory, but you don't know where that directory resides. You can see what directory you are using the command \"pwd\" (print working directory). Issue the command and look at the response. You'll get a slash (\"/\") separated list, known as the path, of the directory hierarchy of your current working directory. On Colab, this will start with \"contents\"\n","\n","Now back to thinking about the command prompt. Since \"ls\" is a program, it most be stored somewhere. It is clearly not in your working directory, because you didn't see it when you executed \"ls\". We can ask the shell to tell us where it found \"ls\" using the \"which ls\" command. Note that \"which\" is also a program. \"which ls\" comes back with \"/bin/ls\", telling you the \"ls\" program is sitting in \"/bin\" directory of the system. \n","\n"]},{"cell_type":"code","metadata":{"id":"W6jeHX12h9Eh","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1599848968645,"user_tz":300,"elapsed":318,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"fcf65e13-ad55-410e-a8aa-06613fe380c6"},"source":["!which ls"],"execution_count":null,"outputs":[{"output_type":"stream","text":["/bin/ls\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"r8uxT_Klh9Er","colab_type":"text"},"source":["Lets see what else is in there by issuing a \"ls /bin\" command. "]},{"cell_type":"code","metadata":{"id":"xZCe7tv0h9Es","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":638},"executionInfo":{"status":"ok","timestamp":1599848976856,"user_tz":300,"elapsed":443,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"2f839897-5fc4-4e93-8e84-c9c7c675f5d2"},"source":["!ls /bin"],"execution_count":null,"outputs":[{"output_type":"stream","text":["bash\t hostname su\n","bunzip2 journalctl sync\n","bzcat\t kill\t systemctl\n","bzcmp\t kmod\t systemd\n","bzdiff\t less\t systemd-ask-password\n","bzegrep lessecho systemd-escape\n","bzexe\t lessfile systemd-hwdb\n","bzfgrep lesskey\t systemd-inhibit\n","bzgrep\t lesspipe systemd-machine-id-setup\n","bzip2\t ln\t systemd-notify\n","bzip2recover login\t systemd-sysusers\n","bzless\t loginctl systemd-tmpfiles\n","bzmore\t ls\t systemd-tty-ask-password-agent\n","cat\t lsblk\t tar\n","chgrp\t lsmod\t tempfile\n","chmod\t mkdir\t touch\n","chown\t mknod\t true\n","cp\t mktemp\t udevadm\n","dash\t more\t ulockmgr_server\n","date\t mount\t umount\n","dd\t mountpoint uname\n","df\t mv\t uncompress\n","dir\t networkctl vdir\n","dmesg\t nisdomainname wdctl\n","dnsdomainname pidof\t which\n","domainname ps\t ypdomainname\n","echo\t pwd\t zcat\n","egrep\t rbash\t zcmp\n","false\t readlink zdiff\n","fgrep\t rm\t zegrep\n","findmnt rmdir\t zfgrep\n","fuser\t run-parts zforce\n","fusermount sed\t zgrep\n","grep\t sh\t zless\n","gunzip\t sh.distrib zmore\n","gzexe\t sleep\t znew\n","gzip\t stty\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"tTReivs8h9E2","colab_type":"text"},"source":["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\". Quick note that MacOS is a bit different and so \"--help\" doesn't seem to work."]},{"cell_type":"code","metadata":{"id":"qEH4msWXh9E4","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"executionInfo":{"status":"ok","timestamp":1599848985431,"user_tz":300,"elapsed":270,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"20bca406-c263-4ca4-908a-f713056969e1"},"source":["!ls --help"],"execution_count":null,"outputs":[{"output_type":"stream","text":["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"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"A7pDyQ5kh9E-","colab_type":"text"},"source":[" 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. "]},{"cell_type":"code","metadata":{"id":"wVVl1XEyh9FB","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":1000},"executionInfo":{"status":"ok","timestamp":1599248224376,"user_tz":300,"elapsed":787,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"9fd4c38c-a857-4c98-c100-3d3a3182fc1f"},"source":["!man ls"],"execution_count":null,"outputs":[{"output_type":"stream","text":["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"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"YhrmDPSdh9FL","colab_type":"text"},"source":["Another command interesting is \"echo\". \"echo\" simply prints whatever you put after it to the screen. "]},{"cell_type":"code","metadata":{"id":"xrwezhlIh9FM","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":34},"executionInfo":{"status":"ok","timestamp":1599849002578,"user_tz":300,"elapsed":355,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"6138bd97-fb07-45c7-8ee9-8abc7ba37149"},"source":["!echo \"Hello World\""],"execution_count":null,"outputs":[{"output_type":"stream","text":["Hello World\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"ic9gNzv_h9FU","colab_type":"text"},"source":["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."]},{"cell_type":"code","metadata":{"id":"eTl0DbMnh9FV","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":54},"executionInfo":{"status":"ok","timestamp":1599849006463,"user_tz":300,"elapsed":290,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"430da2a4-e32a-47e6-b0cd-f4f3f158844c"},"source":["!echo $PATH"],"execution_count":null,"outputs":[{"output_type":"stream","text":["/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"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"Mi7s9XLWh9Fg","colab_type":"text"},"source":["You can set you own environment variables. Different shells have different syntax. Lets first figure out what shell we are running. \n","\n","*Exercise 1:* Use the \"echo\" command to print out the value of the \"SHELL\" environment variable:"]},{"cell_type":"code","metadata":{"id":"xgjPgkShoN-b","colab_type":"code","colab":{"base_uri":"https://localhost:8080/","height":118},"executionInfo":{"status":"ok","timestamp":1599849023514,"user_tz":300,"elapsed":12795,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"b9c8de3e-4d78-496f-edaa-1af6f223ce47"},"source":["!/bin/bash --noediting"],"execution_count":null,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (102): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# echo $SHELL\n","/bin/bash\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"YoEgruUhqvzw"},"source":["## Navigating Directories\n","\n","You can change your current directory using the \"cd\" shell command. Note that \"cd\" is not a Unix program. Once in a directory, you can use the \"ls\" command to list the contents or \"pwd\" to remind yourself your current working directory. You can move back one level in your current directory hierarchy using \"cd ..\". In general \"..\" represents the path to a directory one level above your current directory, \"../..\" represents two levels up, and so on. \".\" represents the current directory. If you look at the PATH environment variable, you'll notice that the last item is \".\", telling the shell to look into your current directory for commands. Finally the \"~\" character always refers to your home directory.\n","\n","Some other file manipulation commands:\n","\n"," - The \"mkdir\" command creates new directories. \n"," - \"cp\" and \"mv\" allow you to copy and move (or rename) files, taking 2 arguments: the original path/filename and the target path/filename. \n"," - The \"rm\" and \"rmdir\" commands remove (delete) files and directories.\n","\n","\n","*Exercise 2:* 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":{"colab_type":"code","id":"A16VzZ3G0J8x","colab":{"base_uri":"https://localhost:8080/","height":151},"executionInfo":{"status":"ok","timestamp":1599849133148,"user_tz":300,"elapsed":60297,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"5c4dec85-89d8-4004-f248-7fb08e8aaa6e"},"source":["!/bin/bash --noediting"],"execution_count":null,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (102): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# mkdir Data-1441\n","\u001b]0;root@ca2265856bf7: /content/sample_data\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# cd Data-1441\n","\u001b]0;root@ca2265856bf7: /content/sample_data/Data-1441\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data/Data-1441\u001b[00m# mkdir Lab-1-Solutions\n","\u001b]0;root@ca2265856bf7: /content/sample_data/Data-1441\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data/Data-1441\u001b[00m# cd Lab-1-Solutions\n","\u001b]0;root@ca2265856bf7: /content/sample_data/Data-1441/Lab-1-Solutions\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content/sample_data/Data-1441/Lab-1-Solutions\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"o38c4lbsqvzy"},"source":["## Exploring Unix Filesystem\n","\n","You can look at the root directory of the system by issuing \"ls /\". As explained in lecture, Unix uses the file system to communicate with devices and between processes. \"/etc\" keeps the configuration files of the system. \"/bin\" and \"/sbin\" store most of the standard Unix programs. \"/usr\" stores installed programs and their associate files, with \"/usr/bin\" usually storing the commands you can run. \n","\n","*Exercise 3:* List the \"/dev\" directory. How many SSD storage devices do you see? How many partitions does each device have? (Answer in box below)"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"yNj2LXzP2ksl","colab":{"base_uri":"https://localhost:8080/","height":168},"executionInfo":{"status":"ok","timestamp":1599344597951,"user_tz":300,"elapsed":29623,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"3f271791-7734-43f8-ef7e-2edcdb2de4ed"},"source":["!/bin/bash --noediting"],"execution_count":null,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (105): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@485520fc9b7d: /content/sample_data\u0007\u001b[01;32mroot@485520fc9b7d\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# ls/dev\n","bash: ls/dev: No such file or directory\n","\u001b]0;root@485520fc9b7d: /content/sample_data\u0007\u001b[01;32mroot@485520fc9b7d\u001b[00m:\u001b[01;34m/content/sample_data\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@485520fc9b7d: /content/sample_data\u0007\u001b[01;32mroot@485520fc9b7d\u001b[00m:\u001b[01;34m/content/sample_data\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"ou5qjbjPQmNC","colab_type":"text"},"source":["SSD storage devices: 7\n","Partitions: 2"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"7P9EG0KOqvz2"},"source":["## Text File Manipulation\n","\n","As explained in lecture, Unix stores most information in text files. For example, the list of all users and their home directories are stored in \"/etc/passwd\". Let get some familiarity with the most commonly used commands to manipulate files.\n","\n"," - You can see the contents contents a file using the \"cat\" (concatenate) command. Try executing \"cat /etc/passwd\". You'll get a huge list that will go by your screen quickly. \n"," \n"," - To go through the file page by page, you can use the \"less\" or \"more\" commands. \n"," \n"," - You can see the first or last N (N=10 by default) lines of a file using \"head\" or \"tail\" commands. For example \"tail -20 /etc/passwd\" will list the last 20 lines. \n"," \n"," - You can search a test file using the \"grep\" command, which takes a string keyword as the first argument and a filename as the second, and by default prints out every line in the file that contrains the string. So for example you can do \"grep \\$USER /etc/passwd\" to find the line corresponding to your account. Some useful flags: \n"," \n"," - \"-i\" ignores the case of the keyword\n"," - \"-v\" display those lines that do NOT match \n"," - \"-n\" precede each matching line with the line number \n"," - \"-c\" print only the total count of matched lines \n"," \n"," For example \"grep -c \\$USER /etc/passwd\" should show that you are in the password file just once. \n"," \n"," - The \"wc\" (word count) command counts the number of lines, words, and characters in a file. By default \"wc\" gives you all three numbers, but \"-w\", \"-l\", or \"-c\" flags \n","\n","*Exercise 4:* Count how many lines in the password file contain the letter \"w\". "]},{"cell_type":"code","metadata":{"colab_type":"code","id":"UlsANMuf2qMs","colab":{"base_uri":"https://localhost:8080/","height":195},"executionInfo":{"status":"ok","timestamp":1599850310801,"user_tz":300,"elapsed":99165,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"4dd31038-dd99-40de-dd26-058f3f4cd72c"},"source":["!/bin/bash --noediting"],"execution_count":2,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (770): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# grep -c w /etc/passwd\n","3\n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\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@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# exit\n","exit\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"SZuhLbD8qvz5"},"source":["## Redirection\n","\n","Unix provides programs \"pipes\" for input and output. Most of what you see on the screen when you run a program was written to the \"stdout\" (standard output) pipe. Other pipes are \"stdin\" (standard input) and \"stderr\" (standard error), where error messages are written.\n","\n","As discussed in lecture, the basic commands of are simple, but you can chain them to do complicated things. Redirection is how you chain these commands, directing the output of one command to the input of the next.\n","\n","As an example, consider the \"cat\" command. Cat takes stdin and outputs it to stdout. Type \"cat\" and press enter and confirm. You can get back to the command prompt by pressing \"control-c\" (sends terminate singal) or \"control-d\" (end of file character). Note that from now on we will use the convention: \"control-d\" = \"^D\"\n","\n","*Exercise 5a:* Using \"cat\" and indirection you can write things into a file. The \">\" symbol directs stdout into a file. Try \"cat > favorite-colors-list.txt\" and then type in your 3 favorite colors, each on it's own line. Use \"^D\" to end your input."]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"H5vxtcXnqvz6"},"source":["Use \"cat\", \"more\", or \"less\" to confirm that you file is as you expect it. \">>\" allows you to append to the file. \n","\n","*Exercise 5b:* Append 2 more colors to your file."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"twRKNaGy3XGw","colab":{"base_uri":"https://localhost:8080/","height":248},"executionInfo":{"status":"ok","timestamp":1599852600404,"user_tz":300,"elapsed":104132,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"d61ebe49-d615-49cc-9485-9dcca5445200"},"source":["!/bin/bash --noediting"],"execution_count":7,"outputs":[{"output_type":"stream","text":["bash: cannot set terminal process group (770): Inappropriate ioctl for device\n","bash: no job control in this shell\n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# cat > favorite-colors-list.txt\n","black\n","white\n","gray\n","\n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# \n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# cat >> favorite-colors-list.txt\n","pink\n","green\n","\n","\u001b]0;root@ca2265856bf7: /content\u0007\u001b[01;32mroot@ca2265856bf7\u001b[00m:\u001b[01;34m/content\u001b[00m# ^C\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"DZODNKiAqvz8"},"source":["The \"sort\" command sorts what it sees on stdin. Instead of taking input from the terminal, you can direct the shell to take stdin from a file using \"<\". Try \"sort < favorite-color-list.txt\" and \"sort < favorite-color-list.txt > sorted-favorite-color-list.txt\".\n","\n","Finally, instead of piping input / output into files, you can directly chain one program into another using \"|\". So for example, you can do \"cat /etc/passwd | grep -i \\$USER | wc -l\". \n","\n","*Exercise 5c:* Use indirection to count the number of users on TACC with your first name. Copy the command you used into box below."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"oP9XlZl_3iZD","colab":{}},"source":["!/bin/bash --noediting"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"v5IaZXNyqvz_"},"source":["## Git\n","\n","`git` is a Version Control System (VCS), typically used to organize the source code of software project but also good source of documents or web-pages. An instance of `git` server stores repositories, each typically containing the code relevant to a specific project. Users create local `clones` of repositories, change and develop the local copies of the code, `commit` the changes to their local repository, `push` to the server as a contribution, \n","`pull` updates from the server, and `merge` changes between local and remote versions. \n","\n","Besides cloning, repositories can be branched or forked. A repository generally starts with a `master` branch that evolves as push requests are merged in. Creating a new branch from an existing branch creates a snapshot of the which can evolve independently or be merged in later. Branches are easy to make and delete, and can serve various purposes. They can represent a stable version of software package. Or a parallel development for different operating system. A fork of a repository is a standalone instance of the repository which can be stored and managed independently from the original, where you can work independently without constraints or interference. \n","\n","[GitHub](github.com) provides a massive publically accessible instance of a `git` system besides sharing code, projects can be developed by the open source community. It provides tools for managing your repository and a wiki for documentation. Contributions to public software on GitHub generally require making a merge request which would be judged by the managers of the repository. That's why most software packages enourage you to create a new fork, so you can work independently.\n","\n","Lets take a look at some repositories:\n","\n","* [This class](https://github.com/UTA-DataScience/DATA1401.2020.Fall)\n","\n","\n","Read through [Version Control System Lecture](https://github.com/UTA-DataScience/VersionControlSystem/blob/master/VersionControlSystem/README.md) to better understand `git`. Note that you do not need to do the exercises at the end of the lecture.\n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"J_R64sQDqv0A"},"source":["## Plan\n","\n","You made a clone of the class repository at start of this lab. We will create a new fork where you can keep track and submit your work, following [these instructions](https://help.github.com/articles/fork-a-repo/).\n","\n","Goto to github.com and log in.\n","\n","Next, lets create a fork of the [class repository](https://github.com/afarbin/DATA1401-Spring-2019). Click the link and press the \"Fork\" button on the top right. Select your repository as where you want to place the fork.\n"]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"edTvE6rOqv0C"},"source":["Now we will check out your fork in your Google Drive / Colab.\n","\n","Note: Jupyter allows you to run shell directly in a notebook. We will use `!` and `%` to call shell commands directly in this notebook. Follow along yourself. Either create a new notebook or open a terminal. \n","\n","Start by listing the contents of your current directory."]},{"cell_type":"code","metadata":{"colab_type":"code","id":"e5tXg0f8qv0D","colab":{}},"source":["!ls"],"execution_count":null,"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":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"fwsBdTnYqv0Q"},"source":["From the github page for your fork, press the green \"Clone or download\" button and copy the URL.\n","\n","Goto to your notebook and use the following command to clone the repository, pasting the URL you just copied:\n"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"8w42MH6Jqv0S","colab":{}},"source":["# What you past here should look like:\n","#!git clone https://github.com//DATA1401.2020.Fall.git"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"cOAuqTVUqv0V"},"source":["Go into the directory:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"b1Ew4tEZqv0X","colab":{}},"source":["%cd DATA1401.2020.Fall\n","!ls"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"IrhWToc-qv0a"},"source":["We will now connect your fork to the original so you can pull changes from there. \n","\n","Check remote status:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"JxtMYR-9qv0c","colab":{}},"source":["!git remote -v"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"9ud3X0fBqv0f"},"source":["Now use the original class URL to set your upstream:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"pgJlKxBqqv0h","colab":{}},"source":["!git remote add upstream https://github.com/UTA-DataScience/DATA1401.2020.Fall"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"colab_type":"code","id":"id2yUEt9qv0k","colab":{}},"source":["!git remote -v"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"sAkgeJ6Iqv0n"},"source":["From now on, you can get the newest version of class material by using:"]},{"cell_type":"code","metadata":{"colab_type":"code","id":"AGDsfTFLqv0o","colab":{}},"source":["!git pull"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"colab_type":"text","id":"u9RAhs5b4vXY"},"source":["We will submit your Lab 1 using git at the next Lab."]}]} \ No newline at end of file From 206d6f5bc62b784dc900b99f54d9af6998e2f8bb Mon Sep 17 00:00:00 2001 From: CelesteEsquivel <60523783+CelesteEsquivel@users.noreply.github.com> Date: Fri, 25 Sep 2020 15:39:47 -0500 Subject: [PATCH 2/3] Add files via upload --- Labs/Lab-2-Solutions.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 Labs/Lab-2-Solutions.ipynb diff --git a/Labs/Lab-2-Solutions.ipynb b/Labs/Lab-2-Solutions.ipynb new file mode 100644 index 0000000..2b198c7 --- /dev/null +++ b/Labs/Lab-2-Solutions.ipynb @@ -0,0 +1 @@ +{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Copy of Lab-2.ipynb","provenance":[{"file_id":"https://github.com/UTA-DataScience/DATA1401.2020.Fall/blob/master/Labs/Lab.2/Lab.2.ipynb","timestamp":1600886443245}],"collapsed_sections":[]},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.8.0"}},"cells":[{"cell_type":"markdown","metadata":{"id":"uk7yc0nadBGa"},"source":["# Lab 2\n","\n","[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/UTA-DataScience/DATA1401.2020.Fall/blob/master/Labs/Lab.2/Lab.2.ipynb)\n"]},{"cell_type":"markdown","metadata":{"id":"u9RAhs5b4vXY"},"source":["\n","## Make your fork private\n","\n","Navigate your fork of the course repository on GitHub and click the \"gear\" icon to change the settings. Select \"Options\" on the left and scroll all the way down. Then click on \"Make Private\" to make your repository private. \n","\n","Next select the collaborators on the left and add your Professor as a collaborator. "]},{"cell_type":"markdown","metadata":{"id":"q-gMWiE4dBG_"},"source":["## Python Programming\n","\n","In the remainder of this lab you will practice python by solving some simple exercises. \n","\n","*Exercise 1:* Write 2 functions `even(x)` and `odd(x)` that take an integer and returns True if the input is even or odd, otherwise returns False. Use cell below for your solution. Use the subsequent cell to demonstrate that your solution works. Feel free to add additional cell as needed using the \"+\" button on the button bar above. "]},{"cell_type":"code","metadata":{"id":"jwN5jff1dBG_"},"source":["# Write you solution here\n","def even(x):\n"," return x%2==0\n","def odd(x):\n"," return x%2!=0"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"xNJAcodhdBHB","executionInfo":{"status":"ok","timestamp":1600886145967,"user_tz":300,"elapsed":657,"user":{"displayName":"","photoUrl":"","userId":""}},"outputId":"06dee0cf-9c43-4e40-9d1b-d6a7b4ab4a3a","colab":{"base_uri":"https://localhost:8080/","height":88}},"source":["# Test your solution here\n","print(\"Testing even 4:\", even(4))\n","print(\"Testing even 5:\", even(5))\n","print(\"Testing odd 4:\", odd(4))\n","print(\"Testing odd 5:\", odd(5))"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Testing even 4: True\n","Testing even 5: False\n","Testing odd 4: False\n","Testing odd 5: True\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"KL_pyzG8dBHD"},"source":["*Exercise 2:* Write a function that takes a list of numbers as input and returns a list of the subset of elements that are less that 10. Test your solution."]},{"cell_type":"code","metadata":{"id":"g8nt0wnldBHE"},"source":["def less_than_ten(lst):\n"," out_list=list()\n"," for element in lst:\n"," if element < 10:\n"," out_list.append(element)\n"," return out_list"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"__HTUWA1dBHH","executionInfo":{"status":"ok","timestamp":1601064406953,"user_tz":300,"elapsed":655,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"94092622-bb7e-43c5-f7b2-78631e7ae018","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["less_than_ten([2,4,6,20,0,10,1])"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[2, 4, 6, 0, 1]"]},"metadata":{"tags":[]},"execution_count":2}]},{"cell_type":"markdown","metadata":{"id":"T0cx91JudBHK"},"source":["*Exercise 3:* Write a function that takes a number `x_max` as input and returns a function that performs the same task as exercise 2, but for `x_max` instead of 10."]},{"cell_type":"code","metadata":{"id":"PqummMcmdBHK"},"source":["def less_than_x(lst,x):\n"," new_list=list()\n"," for element in lst:\n"," if element < x:\n"," new_list.append(element)\n"," return new_list"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"evRYemjXdBHN","executionInfo":{"status":"ok","timestamp":1601064523487,"user_tz":300,"elapsed":399,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"12107161-c895-45cf-8bfe-089d3b004e3f","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["# Test your solution here\n","less_than_x([10,20,40,30,13],30)"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[10, 20, 13]"]},"metadata":{"tags":[]},"execution_count":7}]},{"cell_type":"code","metadata":{"id":"CfkIJzQsQ-gl","executionInfo":{"status":"ok","timestamp":1600886426509,"user_tz":300,"elapsed":22771,"user":{"displayName":"","photoUrl":"","userId":""}},"outputId":"20438af5-54b5-491f-e988-0f8989681faf","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["from google.colab import drive\n","drive.mount('/content/drive')"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Mounted at /content/drive\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"h0I8M27LdBHP"},"source":["*Exercise 4:* Write a function that takes an interger as input and returns a list of all divisors of that number."]},{"cell_type":"code","metadata":{"id":"k6GUpDyrdBHP"},"source":["# Write you solution here\n","def divisor_of_x(x):\n"," divide_x = []\n"," i = 1\n"," while i <= (x):\n"," if x % i == 0:\n"," divide_x.append(i)\n"," i += 1\n"," return divide_x"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"YDvRmft-dBHR","executionInfo":{"status":"ok","timestamp":1601064636636,"user_tz":300,"elapsed":421,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"834f653f-d7b7-41ce-9b38-4afad263eae6","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["# Test your solution here\n","divisor_of_x(81)"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[1, 3, 9, 27, 81]"]},"metadata":{"tags":[]},"execution_count":11}]},{"cell_type":"markdown","metadata":{"id":"IOWnLMvxdBHT"},"source":["*Exercise 5:* Write a function that takes 2 lists as input and returns a list that contains only the elements that are common between the lists (without duplicates). Make sure your program works on two lists of different sizes."]},{"cell_type":"code","metadata":{"id":"tR31bnTDdBHT"},"source":["def common_element(l1,l2):\n"," common_list=list()\n"," for x in l1:\n"," for y in l2:\n"," if x==y and x not in common_list:\n"," common_list.append(x)\n"," return common_list"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"IJDf6ebYdBHV","executionInfo":{"status":"ok","timestamp":1601064792390,"user_tz":300,"elapsed":452,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"332d81f3-5189-4041-ca28-5c8adcef7a32","colab":{"base_uri":"https://localhost:8080/","height":52}},"source":["# Test your solution here\n","print(common_element([1,2,5,6,6,12,15],[6,1,0,15]))\n","print(common_element(['apples', 'tupples', 'a',7,5,4], ['banana', 'tupples',4]))"],"execution_count":null,"outputs":[{"output_type":"stream","text":["[1, 6, 15]\n","['tupples', 4]\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"3vA7M9pldBHX"},"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"},"source":["# Write you solution here\n","def pal(word):\n"," length = len(word)\n"," for x in range(0,length):\n"," if word[x] != word[length -x -1]:\n"," return False\n"," return True"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"v5cmVQ6MdBHZ","executionInfo":{"status":"ok","timestamp":1601064880049,"user_tz":300,"elapsed":446,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"dce6dfdb-7333-4a78-e8d9-7d155c00700a","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["# Test your solution here\n","pal(\"racecar\")"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["True"]},"metadata":{"tags":[]},"execution_count":18}]},{"cell_type":"markdown","metadata":{"id":"fT35xwandBHc"},"source":["*Exercise 7:* Write a Rock-Paper-Scissors game function, that takes 2 strings, the inputs of player 1 and player 2, and output 1 or 2 corresponding to which player wins, or 0 if draw.\n","\n","Implement a Rock-Paper-Scissors game by soliciting input from 2 players, testing with this function, and repeating if there is a draw.\n","\n","Remember the rules:\n","\n","* Rock beats scissors\n","* Scissors beats paper\n","* Paper beats rock"]},{"cell_type":"code","metadata":{"id":"U1_HxxaWdBHd"},"source":["# Write you solution here\n","def ropasc(str1,str2):\n"," str1 , str2 = str1.lower(), str2.lower()\n"," if str1 == str2:\n"," return 0\n"," if (str1 == 'rock' and str2 == 'scissors') and (str1 == 'paper' and str2 == 'rock') and (str1== 'scissors' and str2 == 'paper'):\n"," return 1\n"," else:\n"," return 2"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"ooR2ldZBdBHf","executionInfo":{"status":"ok","timestamp":1601064964024,"user_tz":300,"elapsed":16518,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"9fae7c5d-ad8c-4a30-c2f2-94ee4ea2c257","colab":{"base_uri":"https://localhost:8080/","height":70}},"source":["# Test your solution here\n","player1 = input('Type rock,paper,or scissors:')\n","player2 = input('Type rock,paper,or scissors:')\n","ropasc(player1,player2)"],"execution_count":null,"outputs":[{"output_type":"stream","text":["Type rock,paper,or scissors:paper\n","Type rock,paper,or scissors:scissors\n"],"name":"stdout"},{"output_type":"execute_result","data":{"text/plain":["2"]},"metadata":{"tags":[]},"execution_count":20}]},{"cell_type":"markdown","metadata":{"id":"dJQzXNKzdBHh"},"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"},"source":["# Write you solution here\n","def fibo(n):\n"," Lst=[0,1]\n"," for i in range(n-2):\n"," Lst.append(Lst[-1]+Lst[-2])\n"," return Lst "],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"rzK5FskJdBHj","executionInfo":{"status":"ok","timestamp":1601065109334,"user_tz":300,"elapsed":367,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"5165492d-c907-42d2-f0fc-e371d0477eb4","colab":{"base_uri":"https://localhost:8080/","height":35}},"source":["# Test your solution here\n","fibo(9)"],"execution_count":null,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[0, 1, 1, 2, 3, 5, 8, 13, 21]"]},"metadata":{"tags":[]},"execution_count":26}]},{"cell_type":"markdown","metadata":{"id":"q6c_AskadBHl"},"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"},"source":["# Write you solution here"],"execution_count":null,"outputs":[]},{"cell_type":"code","metadata":{"id":"nQyhnLZ_dBHn"},"source":["# Test your solution here"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"NFSmRaSydBHq"},"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","executionInfo":{"status":"ok","timestamp":1601065778213,"user_tz":300,"elapsed":17762,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"717117cf-3f25-43d9-ca5d-e3f09eb248c3","colab":{"base_uri":"https://localhost:8080/","height":124}},"source":["# Write you solution here\n","def play():\n"," user_input = \"\"\n"," guess = 0\n"," print(guess)\n"," while(user_input != \"correct\"):\n"," user_input = input(guess)\n"," if(user_input == \"higher\"):\n"," guess +=1\n"," elif(user_input == \"lower\"):\n"," guess -=1\n"," elif(user_input == \"correct\"):\n"," print(\"Nice,wanna play agaain?\")\n"," else:\n"," print(\"You typed something wrong. Try again.\")\n","\n","\n","play()"],"execution_count":null,"outputs":[{"output_type":"stream","text":["0\n","higher\n","1higher\n","2higher\n","3correct\n","Nice,wanna play agaain?\n"],"name":"stdout"}]},{"cell_type":"code","metadata":{"id":"6T8YdWSMdBHs"},"source":["# Test your solution here"],"execution_count":null,"outputs":[]}]} \ No newline at end of file From 1ab8b35db560330e66eb102aa88064460c760bde Mon Sep 17 00:00:00 2001 From: CelesteEsquivel <60523783+CelesteEsquivel@users.noreply.github.com> Date: Fri, 30 Oct 2020 14:22:04 -0500 Subject: [PATCH 3/3] Add files via upload --- Copy of Exam.ipynb | 1 + 1 file changed, 1 insertion(+) create mode 100644 Copy of Exam.ipynb diff --git a/Copy of Exam.ipynb b/Copy of Exam.ipynb new file mode 100644 index 0000000..28a4b05 --- /dev/null +++ b/Copy of Exam.ipynb @@ -0,0 +1 @@ +{"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 Exam.ipynb","provenance":[{"file_id":"https://github.com/UTA-DataScience/DATA1401.2020.Fall/blob/master/Exams/Mid-term/Exam.ipynb","timestamp":1604083946757}]}},"cells":[{"cell_type":"markdown","metadata":{"id":"UjacMfbO2fn1"},"source":["# Mid-term Exam\n","\n","[![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/UTA-DataScience/DATA1401.2020.Fall/blob/master/Exams/Mid-term/Exam.ipynb)\n","\n","Add cells to this notebook as you need for your solutions and your test of your solutions."]},{"cell_type":"code","metadata":{"id":"j8RVx1_15Cr7","executionInfo":{"status":"ok","timestamp":1604084622684,"user_tz":300,"elapsed":749,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}}},"source":["import numpy as np"],"execution_count":19,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"r6ds7vWp2fn8"},"source":["1a. 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":"54t3_miu2foA","executionInfo":{"status":"ok","timestamp":1604084482614,"user_tz":300,"elapsed":645,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}}},"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":13,"outputs":[]},{"cell_type":"code","metadata":{"id":"BGQ4N8C925xD","executionInfo":{"status":"ok","timestamp":1604084484280,"user_tz":300,"elapsed":903,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"374147f8-113a-426b-d057-f7c95e20c930","colab":{"base_uri":"https://localhost:8080/","height":36}},"source":["def first_alphabetically(lst):\n"," sorted = list()\n"," min = lst[0]\n"," for i in lst:\n"," if i < min:\n"," min = i\n"," return min\n","first_alphabetically(states)"],"execution_count":14,"outputs":[{"output_type":"execute_result","data":{"application/vnd.google.colaboratory.intrinsic+json":{"type":"string"},"text/plain":["'Alabama'"]},"metadata":{"tags":[]},"execution_count":14}]},{"cell_type":"markdown","metadata":{"id":"i8K-7S_32foT"},"source":["should return the string `\"Alabama\"`. Note that you can compare strings:"]},{"cell_type":"code","metadata":{"id":"ydW1XLg62foX","executionInfo":{"status":"ok","timestamp":1604084486406,"user_tz":300,"elapsed":665,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"d4d08bd0-365f-4da0-a13d-9c161a84b6ec","colab":{"base_uri":"https://localhost:8080/"}},"source":["print(\"A\">\"B\")\n","print(\"B\">\"A\")\n","print(\"A\">\"a\")\n","print(\"bca\">\"bbc\")"],"execution_count":15,"outputs":[{"output_type":"stream","text":["False\n","True\n","False\n","True\n"],"name":"stdout"}]},{"cell_type":"markdown","metadata":{"id":"3jMHbNtZ2fop"},"source":["Make sure your implementation isn't case sensitive. **Do not use** python's built-in `min`, `max`, `sort` or any other sort function you find."]},{"cell_type":"markdown","metadata":{"id":"kG_MM0K-2for"},"source":["1b. Write a function `arg_first_alphabetically(lst)`, which does the same thing as in exercise 1 but returns the index of the first string alphabetically."]},{"cell_type":"code","metadata":{"id":"OHB1jLgr3YpP","executionInfo":{"status":"ok","timestamp":1604084489576,"user_tz":300,"elapsed":648,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"f70b7a68-7774-4341-cabe-0801b44a6285","colab":{"base_uri":"https://localhost:8080/"}},"source":["def arg_first_alphabetically(lst):\n"," min = first_alphabetically(lst)\n"," for i in range(len(lst)):\n"," if lst[i] == min:\n"," return i\n","arg_first_alphabetically(states)"],"execution_count":16,"outputs":[{"output_type":"execute_result","data":{"text/plain":["23"]},"metadata":{"tags":[]},"execution_count":16}]},{"cell_type":"markdown","metadata":{"id":"tK4BCbbl2fow"},"source":["1c. Use your result in question 2 to implement a function `arg_sort_alphabetically(lst)` that returns a list that is alphabetically sorted. Sorting can be accomplished by successively applying the function in question 1 and removing the first element alphabetically. You can remove an element from a list using `pop()`. Make sure your implementation isn't case sensitive. Do not use python's built-in `min`, `max`, `sort` or any other sort function you find."]},{"cell_type":"code","metadata":{"id":"xxKbC3Ax3qtI","executionInfo":{"status":"ok","timestamp":1604084497430,"user_tz":300,"elapsed":681,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"3cabce59-41ad-4bd6-9a90-d58771ec0be2","colab":{"base_uri":"https://localhost:8080/"}},"source":["def arg_sort_alphabetically(lst):\n"," sorted= []\n"," while len(lst)>0:\n"," pos = (arg_first_alphabetically(lst))\n"," sorted.append(lst[pos])\n"," lst.pop(pos)\n"," return (sorted)\n","arg_sort_alphabetically(states)"],"execution_count":17,"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":17}]},{"cell_type":"markdown","metadata":{"id":"y-Kapx0u2foz"},"source":["2. 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":"jSn6PG5r45Tc","executionInfo":{"status":"ok","timestamp":1604084656086,"user_tz":300,"elapsed":786,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"c78e680a-0f2a-40ab-8d16-999381b3963a","colab":{"base_uri":"https://localhost:8080/"}},"source":["def outer_product(a,b):\n"," outer= np.zeros((len(a),len(b)))\n"," for i in range (len(a)):\n"," for j in range (len(b)):\n"," outer[i][j] = a[i]*b[j]\n"," return outer\n","outer_product([1,2],[3,4])"],"execution_count":21,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[3., 4.],\n"," [6., 8.]])"]},"metadata":{"tags":[]},"execution_count":21}]},{"cell_type":"markdown","metadata":{"id":"a8ogcD3H2fo2"},"source":["3a. 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":"ZkNBoocD5fW_","executionInfo":{"status":"ok","timestamp":1604084704820,"user_tz":300,"elapsed":680,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"a040854e-d9f1-4b09-d897-131350e04e88","colab":{"base_uri":"https://localhost:8080/"}},"source":["def cumilative_sum(lst):\n"," for i in range(1,len(lst)):\n"," lst[i] += lst[i-1]\n"," return lst\n","\n","cumilative_sum([1,2,3])"],"execution_count":22,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[1, 3, 6]"]},"metadata":{"tags":[]},"execution_count":22}]},{"cell_type":"markdown","metadata":{"id":"frdUQxoc2fo6"},"source":["3b. 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":"BIjALSQc2fo9"},"source":["$$\n","\\int_{-\\infty}^{x_{90}} N(x;\\mu=0,\\sigma=1) dx = 0.9\n","$$"]},{"cell_type":"code","metadata":{"id":"AWhdFuec2fpA","executionInfo":{"status":"ok","timestamp":1604085002754,"user_tz":300,"elapsed":646,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}}},"source":["import math,random\n","\n","def arange(x_min,x_max,steps=10):\n"," step_size=(x_max-x_min)/steps\n"," x=x_min\n"," out = list()\n"," for i in range(steps):\n"," out.append(x)\n"," x+=step_size\n"," return out\n","\n","def generate_normal(N,m=0,s=1):\n"," out = list() \n"," \n"," while len(out)=bin_edges[i] and d x90:\n"," return i-1\n","\n"],"execution_count":26,"outputs":[]},{"cell_type":"code","metadata":{"id":"ME5rmTan6Lim","executionInfo":{"status":"ok","timestamp":1604085005979,"user_tz":300,"elapsed":712,"user":{"displayName":"celeste esquivel","photoUrl":"https://lh3.googleusercontent.com/a-/AOh14GiOH_x2vPhIFIpCE9cr1ZkuaiQ2mn9UtMedgwY8=s64","userId":"09302908931913256973"}},"outputId":"e5d17e79-05d3-4320-eaa0-2979e3716827","colab":{"base_uri":"https://localhost:8080/"}},"source":["data = generate_normal(10)\n","data"],"execution_count":27,"outputs":[{"output_type":"execute_result","data":{"text/plain":["[-0.7595019467250037,\n"," 2.0062746412991204,\n"," -1.3185421292106545,\n"," 2.5314632573441704,\n"," -0.5709567060204296,\n"," 1.720784953755478,\n"," -1.2561401171688849,\n"," -0.9156177596515729,\n"," 0.73817276640953,\n"," 0.5991503540550571]"]},"metadata":{"tags":[]},"execution_count":27}]},{"cell_type":"markdown","metadata":{"id":"i6QmvdQX2fpS"},"source":["4a. Recall in quiz 1 we implemented parts of a poker game in python. The solution to quiz 1 is below. Modify the `flush`, `straight`, and `straight_flush` functions to return `None` instead of `False` and the highest card (value-wise) instead of \"True\"."]},{"cell_type":"code","metadata":{"id":"EN8i9CRJ2fpW"},"source":["suits = [\"Clubs\", \"Diamonds\", \"Hearts\", \"Spades\"]\n","values = list(range(2,11)) + [ \"Jack\", \"Queen\", \"King\", \"Ace\"]\n","\n","def make_deck():\n"," deck=list()\n"," for suit in suits:\n"," for value in values:\n"," deck.append((suit,value))\n"," return deck\n","\n","def flush(hand):\n"," suit=None\n"," for card in hand:\n"," if suit:\n"," if not card[0]==suit:\n"," return False\n"," else:\n"," suit=card[0]\n"," return True\n","\n","def consecutive(lst): \n"," return sorted(lst) == list(range(min(lst), max(lst)+1)) \n","\n","def straight(hand): \n"," return consecutive([values.index(card[1]) for card in hand])\n","\n","def straight_flush(hand):\n"," return stright(hand) and flush(hand)"],"execution_count":null,"outputs":[]},{"cell_type":"markdown","metadata":{"id":"jr_9iprj2fpq"},"source":["4b. Add two additional functions `three_of_a_kind` and `pair` that work in an analogous manner."]},{"cell_type":"code","metadata":{"id":"TdBh4CNT2fpu"},"source":[""],"execution_count":null,"outputs":[]}]} \ No newline at end of file