Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
156 changes: 120 additions & 36 deletions Game.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"# Exercise 1: Can YOU call Mr. OS?\n",
"# Hint: import os\n"
"# Hint: \n",
"import os\n"
]
},
{
Expand All @@ -48,9 +49,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 4,
"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",
Expand All @@ -77,13 +87,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# Exercise 2: Can YOU tell Mr. OS to create the directories \n",
"# \"cybergear\", \"cyberpack\", and \"cyberweapons\"?\n",
"# Hint: os.mkdir(<name-of-directory>)\n"
"# Hint: os.mkdir(<name-of-directory>)\n",
"os.mkdir(\"cybergear\")\n",
"os.mkdir(\"cyberpack\")\n",
"os.mkdir(\"cyberweapons\")"
]
},
{
Expand All @@ -95,9 +108,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 6,
"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",
Expand Down Expand Up @@ -126,9 +147,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"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",
Expand All @@ -144,12 +173,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"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",
"myFile = open(\"cyberweapons/Virus.txt\", \"w+\")"
]
},
{
Expand All @@ -161,9 +191,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"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",
Expand All @@ -189,13 +228,16 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"# Exercise 4: Write \"YOU HAVE BEEN INFECTED\" into the file contents \n",
"# of cyberweapons/Virus\n",
"# hint: open(<name-of-file>, <permissions>) and using the file write command\n"
"# hint: open(<name-of-file>, <permissions>) and using the file write command\n",
"file = open(\"cyberweapons/Virus.txt\", \"w\")\n",
"file.write(\"YOU HAVE BEEN INFECTED\")\n",
"file.close()"
]
},
{
Expand All @@ -207,9 +249,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 23,
"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",
Expand All @@ -230,7 +280,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 24,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,12 +298,14 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 26,
"metadata": {},
"outputs": [],
"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 gear in cybergear_contents:\n",
" file = open(\"cybergear/\" + gear, \"w+\")"
]
},
{
Expand All @@ -267,7 +319,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 27,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -300,7 +352,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -321,13 +373,15 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 30,
"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 treasure in treasure_chest_contents[:6]:\n",
" file = open(\"cyberpack/\" + treasure, \"w+\")"
]
},
{
Expand All @@ -339,7 +393,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 31,
"metadata": {
"scrolled": true
},
Expand Down Expand Up @@ -380,7 +434,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -401,12 +455,13 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"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']"
]
},
{
Expand All @@ -418,12 +473,23 @@
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"execution_count": 54,
"metadata": {
"scrolled": true
},
"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",
Expand All @@ -448,12 +514,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 69,
"metadata": {},
"outputs": [],
"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",
"import shutil\n",
"shutil.rmtree(\"cyberweapons\")\n",
"shutil.rmtree(\"cyberpack\")\n",
"shutil.rmtree(\"cybergear\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -472,7 +556,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down