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
189 changes: 149 additions & 40 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": 1,
"metadata": {},
"outputs": [],
"source": [
"# Exercise 1: Can YOU call Mr. OS?\n",
"# Hint: import os\n"
"# Hint: import os\n",
"import os\n"
]
},
{
Expand All @@ -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",
Expand All @@ -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(<name-of-directory>)\n"
"# Hint: os.mkdir(<name-of-directory>)\n",
"os.makedirs('cyberweapons')"
]
},
{
Expand All @@ -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",
Expand Down Expand Up @@ -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\")"
]
},
{
Expand All @@ -144,7 +185,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 61,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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",
Expand All @@ -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(<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 +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",
Expand All @@ -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\"]"
]
},
{
Expand All @@ -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/')"
]
},
{
Expand All @@ -267,7 +343,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 77,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -300,7 +376,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 78,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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"
]
},
{
Expand All @@ -339,7 +419,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 82,
"metadata": {
"scrolled": true
},
Expand Down Expand Up @@ -380,7 +460,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 85,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -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']"
]
},
{
Expand All @@ -418,9 +499,18 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 87,
"metadata": {},
"outputs": [],
"outputs": [
{
"ename": "SyntaxError",
"evalue": "invalid syntax (<ipython-input-87-c998791c2b55>, line 2)",
"output_type": "error",
"traceback": [
"\u001b[0;36m File \u001b[0;32m\"<ipython-input-87-c998791c2b55>\"\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",
Expand Down Expand Up @@ -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": {
Expand All @@ -472,7 +581,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down