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
239 changes: 190 additions & 49 deletions Game.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,26 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 7,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Why hullo there, Dora!\n",
"\n"
]
}
],
"source": [
"# Exercise 1: Can YOU call Mr. OS?\n",
"# Hint: import os\n"
"# Hint: import os\n",
"import os\n",
"try:\n",
" print(os.popen(\"echo 'Why hullo there, Dora!'\").read())\n",
"except:\n",
" raise Exception(\"He's not here yet! Go back and import him! Remember the 'import' command!\")"
]
},
{
Expand Down Expand Up @@ -77,13 +91,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 10,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Maravilloso! Welcome, my new friends!\n"
]
}
],
"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",
"\n",
"cybergear_is_directory = os.path.isdir(\"cybergear\")\n",
"cyberpack_is_directory = os.path.isdir(\"cyberpack\")\n",
"cyberweapons_is_directory = os.path.isdir(\"cyberweapons\")\n",
"if (cybergear_is_directory and cyberpack_is_directory and cyberweapons_is_directory):\n",
" print(\"Maravilloso! Welcome, my new friends!\")\n",
"else:\n",
" raise Exception(\"I don't see our new friends anywhere!\")\n",
" listdir"
]
},
{
Expand Down Expand Up @@ -126,9 +157,17 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 11,
"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 +183,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 33,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Yay! We have a Virus.txt weapon!\n",
"['Virus.txt']\n"
]
}
],
"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 Virus.txt')\n",
"items_in_cyberweapons = os.listdir(\"cyberweapons\")\n",
"if \"Virus.txt\" in items_in_cyberweapons:\n",
" print(\"Yay! We have a Virus.txt weapon!\")\n",
"elif len(items_in_cyberweapons) == 0:\n",
" raise Exception(\"The directory cyberweapons is still empty!\")\n",
"else:\n",
" raise Exception(\"I'm glad we have weapons, but we need a weapon named Virus for this to work!\")\n",
"print(items_in_cyberweapons)"
]
},
{
Expand Down Expand Up @@ -189,13 +246,30 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 52,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"This looks great!\n"
]
}
],
"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",
"open(\"Virus.txt\",'r') \n",
"fn = \"cyberweapons/Virus.txt\"\n",
"file = open(fn, 'r')\n",
"virus_contents = file.read()\n",
"if virus_contents == \"YOU HAVE BEEN INFECTED\":\n",
" print(\"This looks great!\")\n",
"else:\n",
" raise Exception(\"Please go back, and make sure everything is spelled right!\")\n",
" "
]
},
{
Expand Down Expand Up @@ -230,7 +304,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 45,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -248,12 +322,32 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 43,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Great! It looks like cybergear has the right contents!\n"
]
}
],
"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('touch cyberwatch')\n",
"os.system('touch cyberrouter')\n",
"os.system('touch cyberflashlight')\n",
"os.system('touch cybercable')\n",
"os.system('touch cyberswitch')\n",
"os.system('touch cyberutilitybelt')\n",
"import os\n",
"cybergear_files = os.listdir(\"cybergear\")\n",
"for item in cybergear_contents:\n",
" if item not in cybergear_files:\n",
" raise Exception(\"It looks like there are still some items missing, amigo!\")\n",
"print(\"Great! It looks like cybergear has the right contents!\")"
]
},
{
Expand All @@ -267,17 +361,9 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Great! It looks like cybergear has the right contents!\n"
]
}
],
"outputs": [],
"source": [
"# Run this code to test that you have successfully added the list to\n",
"# the cybergear directory\n",
Expand All @@ -300,7 +386,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 44,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -321,13 +407,35 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 47,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We did it! We did it! Yay! Lo hicimos!\n"
]
}
],
"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",
"os.system('touch taco')\n",
"os.system('touch quesadilla')\n",
"os.system('touch burrito')\n",
"os.system('touch chicharron')\n",
"os.system('touch pupusa')\n",
"i = 0\n",
"cyberpack_contents = os.listdir(\"cyberpack\")\n",
"for item in cyberpack_contents:\n",
" if item in treasure_chest_contents:\n",
" i += 1\n",
"if i >= 5:\n",
" print(\"We did it! We did it! Yay! Lo hicimos!\")\n",
"else:\n",
" raise Exception(\"Please add five items from the treasure chest into the cyberpack directory.\")"
]
},
{
Expand All @@ -339,19 +447,11 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"We did it! We did it! Yay! Lo hicimos!\n"
]
}
],
"outputs": [],
"source": [
"# Run this code to test if you successfully completed Exercise 6!\n",
"i = 0\n",
Expand Down Expand Up @@ -380,7 +480,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -401,12 +501,27 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 59,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"SWIPER NO SWIPING!\n",
"YOU HAVE BEEN INFECTED\n"
]
}
],
"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 = \"dmlydXNjb2Rl\"\n",
"if activation_code == \"dmlydXNjb2Rl\":\n",
" print(\"SWIPER NO SWIPING!\")\n",
" print(os.popen(\"cat cyberweapons/Virus.txt\").read())\n",
"else:\n",
" raise Exception(\"Hurry! Swiper is getting away!\")"
]
},
{
Expand Down Expand Up @@ -448,12 +563,38 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 62,
"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"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'cybergear' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-74-012fb9cb12e3>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msystem\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\" rm -rf \"\u001b[0m \u001b[0;34m/\u001b[0m\u001b[0mcybergear\u001b[0m \u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'cybergear' is not defined"
]
}
],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -472,7 +613,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.4"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down