From d5fe4b67ae8b472b39a0d528c7a1df3ab60ed4f1 Mon Sep 17 00:00:00 2001 From: Asomiddin Rustamov Date: Sat, 4 Apr 2020 17:13:10 -0400 Subject: [PATCH] final Game.ipynb --- Game.ipynb | 204 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 164 insertions(+), 40 deletions(-) diff --git a/Game.ipynb b/Game.ipynb index ef08be6..8ecf1cb 100644 --- a/Game.ipynb +++ b/Game.ipynb @@ -29,12 +29,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "# Exercise 1: Can YOU call Mr. OS?\n", - "# Hint: import os\n" + "# Hint: import os\n", + "import os" ] }, { @@ -48,9 +49,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Why hullo there, Dora!\n", + "\n" + ] + } + ], "source": [ "# Run this to test your code in Exercise 1\n", "try:\n", @@ -77,13 +87,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, "outputs": [], "source": [ "# Exercise 2: Can YOU tell Mr. OS to create the directories \n", "# \"cybergear\", \"cyberpack\", and \"cyberweapons\"?\n", - "# Hint: os.mkdir()\n" + "# Hint: os.mkdir()\n", + "\n", + "os.mkdir('cyberweapons')\n", + "\n" ] }, { @@ -95,9 +108,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 19, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Maravilloso! Welcome, my new friends!\n" + ] + } + ], "source": [ "# Run this code to test that you have created the three files from the\n", "# exercise above\n", @@ -126,13 +147,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 20, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[]\n" + ] + } + ], "source": [ "# Run the following command to see all your items in cyberpack\n", "items_in_cyberweapons = os.listdir(\"cyberweapons\")\n", - "print(items_in_cyberweapons)" + "print(items_in_cyberweapons)\n" ] }, { @@ -144,12 +173,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 51, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 51, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Exercise 3: Can YOU create some files in the cyberweapons directory?\n", - "# hint: Use the os.system() command\n" + "# hint: Use the os.system() command\n", + "os.system('touch cyberweapons/Virus.txt')\n" ] }, { @@ -161,9 +202,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Yay! We have a Virus.txt weapon!\n", + "['Virus.txt']\n" + ] + } + ], "source": [ "# Run this to test your code in Exercise 3\n", "items_in_cyberweapons = os.listdir(\"cyberweapons\")\n", @@ -189,13 +239,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, "outputs": [], "source": [ "# Exercise 4: Write \"YOU HAVE BEEN INFECTED\" into the file contents \n", "# of cyberweapons/Virus\n", - "# hint: open(, ) and using the file write command\n" + "# hint: open(, ) and using the file write command\n", + "filename = \"cyberweapons/Virus.txt\"\n", + "f = open(filename, 'w')\n", + "text = f.write(\"YOU HAVE BEEN INFECTED\")\n", + "f.close()" ] }, { @@ -207,9 +261,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 54, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "This looks great!\n" + ] + } + ], "source": [ "# Test to see if the above coding snippet has run successfully\n", "fn = \"cyberweapons/Virus.txt\"\n", @@ -230,7 +292,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 55, "metadata": {}, "outputs": [], "source": [ @@ -248,12 +310,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 68, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 68, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Exercise 5: for each item in cybergear_contents, \n", - "# create files of the same name in the cybergear directory\n" + "# create files of the same name in the cybergear directory\n", + "os.system('cd cybergear')\n", + "for file in cybergear_contents:\n", + " os.system('touch ' + 'cybergear/' + file)\n", + "os.system('ls cybergear')\n" ] }, { @@ -267,7 +344,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 69, "metadata": {}, "outputs": [ { @@ -300,7 +377,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 70, "metadata": {}, "outputs": [], "source": [ @@ -321,13 +398,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 74, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "# Exercise 6: Can YOU put only five items from treasure_chest_contents \n", "# into the cyberpack directory?\n", - "# hint: This will require the use of the for loop and touch command\n" + "# hint: This will require the use of the for loop and touch command\n", + "i = 1\n", + "for file in treasure_chest_contents:\n", + " if i <= 5:\n", + " os.system('touch ' + 'cyberpack/' + file)\n", + " i = i + 1\n" ] }, { @@ -339,7 +432,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 75, "metadata": { "scrolled": true }, @@ -380,7 +473,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, "outputs": [], "source": [ @@ -401,12 +494,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 77, "metadata": {}, "outputs": [], "source": [ "# Exercise 7: Store the value in \"viruscode\" in the variable \"activation_code\"\n", - "# hint: value_of_attribute = dictionary[\"attribute\"]\n" + "# hint: value_of_attribute = dictionary[\"attribute\"]\n", + "\n", + "activation_code = dictionary_of_codes['viruscode']" ] }, { @@ -418,12 +513,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 79, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "SWIPER NO SWIPING!\n", + "YOU HAVE BEEN INFECTED\n" + ] + } + ], "source": [ "# Activate the Virus.txt!\n", - "if activation_code == \"dmlydXNjb2Rl\"\n", + "if activation_code == \"dmlydXNjb2Rl\":\n", " print(\"SWIPER NO SWIPING!\")\n", " print(os.popen(\"cat cyberweapons/Virus.txt\").read())\n", "else:\n", @@ -448,12 +552,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 82, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Exercise 8: Remove all cyber directories using the os.system() command\n" + "# Exercise 8: Remove all cyber directories using the os.system() command\n", + "\n", + "os.system('rm -rf cyberweapons')" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -472,7 +596,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4,