diff --git a/Game.ipynb b/Game.ipynb index ef08be6..dba9a1b 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\n" ] }, { @@ -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,14 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "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", + "os.makedirs('cyberweapons')" ] }, { @@ -95,9 +106,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "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 +145,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 60, + "metadata": { + "scrolled": false + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Virus.txt']\n" + ] + }, + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 60, + "metadata": {}, + "output_type": "execute_result" + } + ], "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", + "\n", + "os.system(\"touch cyberweapons/Virus.txt\")" ] }, { @@ -144,7 +185,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 61, "metadata": {}, "outputs": [], "source": [ @@ -161,9 +202,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 62, "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,16 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "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", + "file = open(\"cyberweapons/Virus.txt\", \"w\")\n", + "file.write(\"YOU HAVE BEEN INFECTED\")\n", + "file.close()" ] }, { @@ -207,9 +260,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 65, "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,13 +291,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 74, "metadata": {}, "outputs": [], "source": [ "# Run the following code to initialize cybergear contents\n", - "cybergear_contents = [\"cyberwatch\", \"cyberflashlight\", \"cyberswitch\", \n", - " \"cyberrouter\", \"cybercable\", \"cyberutilitybelt\"]" + "cybergear_contents = [\"cyberwatch\", \"cyberflashlight\", \"cyberswitch\", \"cyberrouter\", \"cybercable\", \"cyberutilitybelt\"]" ] }, { @@ -248,12 +308,28 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 76, + "metadata": { + "scrolled": true + }, + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 76, + "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", + "for file in cybergear_contents:\n", + " os.system(\"touch + cybergear/\" + file)\n", + "os.system('ls cybergear/')" ] }, { @@ -267,7 +343,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 77, "metadata": {}, "outputs": [ { @@ -300,7 +376,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 78, "metadata": {}, "outputs": [], "source": [ @@ -321,13 +397,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 80, "metadata": {}, "outputs": [], "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", + "for file in treasure_chest_contents:\n", + " if i <=5:\n", + " os.system(\"touch + cyberpack/\" + file)\n", + " i = i + 1" ] }, { @@ -339,7 +419,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 82, "metadata": { "scrolled": true }, @@ -380,7 +460,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 85, "metadata": {}, "outputs": [], "source": [ @@ -401,12 +481,13 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 86, "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", + "activation_code = dictionary_of_codes['viruscode']" ] }, { @@ -418,9 +499,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 87, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (, line 2)", + "output_type": "error", + "traceback": [ + "\u001b[0;36m File \u001b[0;32m\"\"\u001b[0;36m, line \u001b[0;32m2\u001b[0m\n\u001b[0;31m if activation_code == \"dmlydXNjb2Rl\"\u001b[0m\n\u001b[0m ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ "# Activate the Virus.txt!\n", "if activation_code == \"dmlydXNjb2Rl\"\n", @@ -448,12 +538,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 88, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 88, + "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", + "os.system('rm -rf cyber*')" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { @@ -472,7 +581,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.4" + "version": "3.7.6" } }, "nbformat": 4,