From 0b07b61dbba7d25f83a3a9d3c54e2ed21af2b91a Mon Sep 17 00:00:00 2001 From: BenjaminPerraut Date: Sun, 27 Feb 2022 20:31:14 +0100 Subject: [PATCH 1/3] benjaminperraut --- your-code/challenge-1.ipynb | 307 ++++++++++++++++++++++++++++++++---- your-code/challenge-2.ipynb | 4 +- 2 files changed, 282 insertions(+), 29 deletions(-) diff --git a/your-code/challenge-1.ipynb b/your-code/challenge-1.ipynb index c574eba..839f327 100644 --- a/your-code/challenge-1.ipynb +++ b/your-code/challenge-1.ipynb @@ -15,7 +15,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], "source": [ @@ -33,12 +33,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Durante un tiempo no estuvo segura de si su marido era su marido'" + ] + }, + "execution_count": 3, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "str_list = ['Durante', 'un', 'tiempo', 'no', 'estuvo', 'segura', 'de', 'si', 'su', 'marido', 'era', 'su', 'marido']\n", - "# Your code here:\n" + "# Your code here:\n", + "' '.join(str_list)\n" ] }, { @@ -50,12 +62,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 37, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "'Grocery list: bananas, chocolate, bread, diapers, ice cream, brownie mix, broccoli.'" + ] + }, + "execution_count": 37, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "food_list = ['Bananas', 'Chocolate', 'bread', 'diapers', 'Ice Cream', 'Brownie Mix', 'broccoli']\n", - "# Your code here:\n" + "# Your code here:\n", + "\"Grocery list: \"+\", \".join(food_list).lower()+\".\"" ] }, { @@ -69,15 +93,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 49, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The area of the circle with radius: 4.5*3 is: 14\n" + ] + } + ], "source": [ "import math\n", "\n", "string1 = \"The area of the circle with radius:\"\n", "string2 = \"is:\"\n", "radius = 4.5\n", + "pi = math.pi\n", "\n", "def area(x, pi = math.pi):\n", " # This function takes a radius and returns the area of a circle. We also pass a default value for pi.\n", @@ -90,7 +123,10 @@ " # Your code here:\n", " return pi * (x**2)\n", " \n", - "# Your output string here:\n" + "# Your output string here:\n", + "print(f'{string1} {radius}*{round(pi)} {string2} {round(radius*pi)}')\n", + "\n", + "#I´m not sure to understand why I have this error about pi is not define while it was definetly defined in the function " ] }, { @@ -106,9 +142,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Some', 'say', 'the', 'world', 'will', 'end', 'in', 'fire', 'Some', 'say', 'in', 'ice', 'From', 'what', 'I’ve', 'tasted', 'of', 'desire', 'I', 'hold', 'with', 'those', 'who', 'favor', 'fire', 'But', 'if', 'it', 'had', 'to', 'perish', 'twice', 'I', 'think', 'I', 'know', 'enough', 'of', 'hate', 'To', 'say', 'that', 'for', 'destruction', 'ice', 'Is', 'also', 'great', 'And', 'would', 'suffice']\n" + ] + } + ], "source": [ "poem = \"\"\"Some say the world will end in fire,\n", "Some say in ice.\n", @@ -120,7 +164,12 @@ "Is also great\n", "And would suffice.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "split_word = [word.strip(\" ,.\") for word in poem.split()]\n", + "print(split_word)\n", + "\n", + "word_dict = {}\n", + "\n" ] }, { @@ -132,9 +181,144 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 34, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['a',\n", + " 's',\n", + " 'a',\n", + " 'i',\n", + " 't',\n", + " 'i',\n", + " 't',\n", + " 'l',\n", + " 'a',\n", + " 't',\n", + " 'a',\n", + " 't',\n", + " 'i',\n", + " 'a',\n", + " 's',\n", + " 'a',\n", + " 'i',\n", + " 't',\n", + " 't',\n", + " 'l',\n", + " 'i',\n", + " 't',\n", + " 't',\n", + " 'a',\n", + " 't',\n", + " 'i',\n", + " 'a',\n", + " 't',\n", + " 'i',\n", + " 't',\n", + " 'i',\n", + " 'a',\n", + " 's',\n", + " 'i',\n", + " 't',\n", + " 'i',\n", + " 'i',\n", + " 't',\n", + " 't',\n", + " 'a',\n", + " 's',\n", + " 's',\n", + " 'i',\n", + " 't',\n", + " 'i',\n", + " 't',\n", + " 's',\n", + " 'i',\n", + " 'l',\n", + " 's',\n", + " 'i',\n", + " 't',\n", + " 's',\n", + " 't',\n", + " 'c',\n", + " 'i',\n", + " 't',\n", + " 'l',\n", + " 'i',\n", + " 'l',\n", + " 's',\n", + " 'i',\n", + " 't',\n", + " 'b',\n", + " 't',\n", + " 'a',\n", + " 'a',\n", + " 'i',\n", + " 't',\n", + " 'i',\n", + " 'l',\n", + " 'l',\n", + " 'i',\n", + " 't',\n", + " 'b',\n", + " 'a',\n", + " 'a',\n", + " 'l',\n", + " 'b',\n", + " 'i',\n", + " 't',\n", + " 'b',\n", + " 'l',\n", + " 'i',\n", + " 't',\n", + " 's',\n", + " 'i',\n", + " 'k',\n", + " 't',\n", + " 'a',\n", + " 't',\n", + " 'i',\n", + " 't',\n", + " 'a',\n", + " 's',\n", + " 'i',\n", + " 'i',\n", + " 't',\n", + " 'a',\n", + " 's',\n", + " 't',\n", + " 'l',\n", + " 't',\n", + " 'i',\n", + " 't',\n", + " 'a',\n", + " 'i',\n", + " 'l',\n", + " 't',\n", + " 'l',\n", + " 't',\n", + " 'i',\n", + " 'l',\n", + " 'a',\n", + " 's',\n", + " 't',\n", + " 's',\n", + " 't',\n", + " 't',\n", + " 'c',\n", + " 'b',\n", + " 'a',\n", + " 't',\n", + " 't',\n", + " 't']" + ] + }, + "execution_count": 34, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "blacklist = ['and', 'as', 'an', 'a', 'the', 'in', 'it']\n", "\n", @@ -158,7 +342,11 @@ "In the morning glad I see; \n", "My foe outstretched beneath the tree.\"\"\"\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "\n", + "#first try with re.findall('[blacklist()]',poem) didn´t work out \n", + "\n" ] }, { @@ -172,16 +360,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 53, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "['T', 'P']" + ] + }, + "execution_count": 53, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "import re\n", "\n", "poem = \"\"\"The apparition of these faces in the crowd;\n", "Petals on a wet, black bough.\"\"\"\n", "\n", - "# Your code here:\n" + "upper_letter = re.findall('[A-Z]', poem)\n", + "upper_letter\n" ] }, { @@ -193,13 +393,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 64, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc\n", + "abc123\n", + "JohnSmith1\n", + "ABBY4\n", + "this block doesn´t have number aka none\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", "\n", - "# Your code here:\n" + "# Your code here:\n", + "for block in data:\n", + " research_num = re.search(\"[0-9]\",block)\n", + " if research_num:\n", + " print(research_num.string)\n", + " else:\n", + " print(\"this block doesn´t have number aka none\")\n" ] }, { @@ -215,18 +433,53 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "123abc\n", + "this block doesn´t have number aka none\n", + "this block doesn´t have number aka none\n", + "this block doesn´t have number aka none\n", + "this block doesn´t have number aka none\n" + ] + } + ], "source": [ "data = ['123abc', 'abc123', 'JohnSmith1', 'ABBY4', 'JANE']\n", - "# Your code here:\n" + "# Your code here:\n", + "\n", + "for block in data:\n", + " research_num = re.search(\"[0-9]\" + \"[a-z]\",block)\n", + " if research_num:\n", + " print(research_num.string)\n", + " else:\n", + " print(\"this block doesn´t have number aka none\")\n", + "#I really check internet every but can´t find the right operator stated in all pages. tried multiple times. \n", + "# found this https://stackoverflow.com/questions/42136040/how-to-combine-multiple-regex-into-single-one-in-python but + doesn´t work as expected " ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -240,7 +493,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.7" } }, "nbformat": 4, diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 6873bd2..ebd2bf5 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -304,7 +304,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3", + "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, @@ -318,7 +318,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.8" + "version": "3.9.7" } }, "nbformat": 4, From bc776ac41400720e0e8be903397f72524ff0bb08 Mon Sep 17 00:00:00 2001 From: BenjaminPerraut Date: Tue, 1 Mar 2022 16:26:54 +0100 Subject: [PATCH 2/3] benjaminPerraut --- your-code/challenge-2.ipynb | 86 ++++++++++++++++++++++++++++++------- 1 file changed, 70 insertions(+), 16 deletions(-) diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index ebd2bf5..556edce 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,11 +72,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 84, "metadata": {}, "outputs": [], "source": [ - "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']" + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "\n", + "#at the begining and based on the question, I thought I had to amend the current code with the real path from my pc \n", + "\n", + "#docs = [r'C:\\Users\\benja\\IronHack\\1-week-Basic\\tutorial_lab\\lab-string-operations\\your-codedoc1.txt', \n", + " #r'C:\\Users\\benja\\IronHack\\1-week-Basic\\tutorial_lab\\lab-string-operations\\your-code\\doc2.txt', \n", + " #r'C:\\Users\\benja\\IronHack\\1-week-Basic\\tutorial_lab\\lab-string-operations\\your-code\\doc3.txt']\n", + "\n", + "\n", + "\n" ] }, { @@ -88,11 +97,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 75, "metadata": {}, "outputs": [], "source": [ - "# Write your code here\n" + "corpus = [open(doc).read() for doc in docs]\n", + "\n", + "#it took me ages to find out this solution, as I was focusing on printing the path within the docs function. \n", + "#with open(r\"C:\\Users\\benja\\IronHack\\1-week-Basic\\tutorial_lab\\lab-string-operations\\your-code\\doc1.txt\") as file_in:\n", + " #corpus = []\n", + " #for line in file_in:\n", + " #corpus.append(line)" ] }, { @@ -104,10 +119,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 76, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" + ] + } + ], + "source": [ + "print(corpus)" + ] }, { "cell_type": "markdown", @@ -132,11 +157,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 82, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n" + ] + } + ], "source": [ - "# Write your code here" + "for string in corpus:\n", + " string.replace('.', '')\n", + " string.lower()\n", + " \n", + "print(corpus)" ] }, { @@ -148,10 +185,12 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 83, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "bag_of_words = []" + ] }, { "cell_type": "markdown", @@ -200,11 +239,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 73, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (Temp/ipykernel_18976/1639485605.py, line 4)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m File \u001b[1;32m\"C:\\Users\\benja\\AppData\\Local\\Temp/ipykernel_18976/1639485605.py\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m terms in bag_of_words:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], "source": [ - "# Write your code here\n" + "term_freq = []\n", + "\n", + "for i in corpus:\n", + " terms in bag_of_words:\n", + " count += 1\n", + " term_freq.append(count)\n" ] }, { @@ -262,7 +315,8 @@ "source": [ "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", "\n", - "# Write your code below\n" + "# Write your code below\n", + "\n" ] }, { From 41531dfffb13c55e0e2235f762725efded4af8d6 Mon Sep 17 00:00:00 2001 From: BenjaminPerraut Date: Sun, 6 Mar 2022 19:35:32 +0100 Subject: [PATCH 3/3] benjaminPerraut --- your-code/GAME.ipynb | 242 ++++++++++++++++++++++++++++++++++++ your-code/challenge-2.ipynb | 97 ++++++++++----- 2 files changed, 310 insertions(+), 29 deletions(-) create mode 100644 your-code/GAME.ipynb diff --git a/your-code/GAME.ipynb b/your-code/GAME.ipynb new file mode 100644 index 0000000..f334368 --- /dev/null +++ b/your-code/GAME.ipynb @@ -0,0 +1,242 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "ca6d6553", + "metadata": {}, + "outputs": [], + "source": [ + "# -*- coding: utf-8 -*-\n", + "# define rooms and items\n", + "\n", + "couch = {\n", + " \"name\": \"couch\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "queen_bed = {\n", + " \"name\": \"queen bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "double_bed = {\n", + " \"name\": \"double bed\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "dresser = {\n", + " \"name\": \"dresser\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "door_a = {\n", + " \"name\": \"door a\",\n", + " \"type\": \"door\",\n", + "}\n", + "#door added for bedroom 2 - Ben\n", + "door_b = {\n", + " \"name\": \"door b\",\n", + " \"type\": \"door\",\n", + "}\n", + "\n", + "key_a = {\n", + " \"name\": \"key for door a\",\n", + " \"type\": \"key\",\n", + " \"target\": door_a,\n", + "}\n", + "\n", + "#Items added for bedroom 2 - Ben\n", + "key_c = {\n", + " \"name\": \"key for door c\", \n", + " \"type\": \"key\", \n", + " \"target\": door_c,\n", + "}\n", + "\n", + "#Items added for bedroom 2 -Ben\n", + "key_d = {\n", + " \"name\": \"key for door d\", \n", + " \"type\": \"key\", \n", + " \"target\": door_d,\n", + "}\n", + "\n", + "piano = {\n", + " \"name\": \"piano\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "keyboard = {\n", + " \"name\": \"keyboard\",\n", + " \"type\": \"furniture\",\n", + "}\n", + "\n", + "game_room = {\n", + " \"name\": \"game room\",\n", + " \"type\": \"room\",\n", + "}\n", + "bedroom = {\n", + " \"name\": \"bedroom 2\",\n", + " \"type\": \"room\",\n", + "}\n", + "\n", + "\n", + "outside = {\n", + " \"name\": \"outside\"\n", + "}\n", + "\n", + "all_rooms = [game_room, bed_room_1, bed_room_2, living_room, outside]\n", + "\n", + "\n", + "all_doors = [door_a]\n", + "\n", + "# define which items/rooms are related\n", + "\n", + "object_relations = {\n", + " \"game room\": [couch, piano, door_a],\n", + " \"outside\": [door_a],\n", + " \"door a\": [game_room, bed_room_1 outside]\n", + " \"door b\": [bedroom_1, bedroom_2]\n", + " \"door c\": [door_c]\n", + " \"bed_room_2\":[key_c,]\n", + "}\n", + "\n", + "# define game state. Do not directly change this dict. \n", + "# Instead, when a new game starts, make a copy of this\n", + "# dict and use the copy to store gameplay state. This \n", + "# way you can replay the game multiple times.\n", + "\n", + "INIT_GAME_STATE = {\n", + " \"current_room\": game_room,\n", + " \"keys_collected\": [],\n", + " \"target_room\": outside\n", + "}\n", + "def linebreak():\n", + " \n", + " print(\"\\n\\n\")\n", + "\n", + "def start_game():\n", + " \n", + " print(\"You wake up on a couch and find yourself in a strange house with no windows which you have never been to before. You don't remember why you are here and what had happened before. You feel some unknown danger is approaching and you must get out of the house, NOW!\")\n", + " play_room(game_state[\"current_room\"])\n", + "\n", + "def play_room(room):\n", + " \n", + " game_state[\"current_room\"] = room\n", + " if(game_state[\"current_room\"] == game_state[\"target_room\"]):\n", + " print(\"Congrats! You escaped the room!\")\n", + " else:\n", + " print(\"You are now in \" + room[\"name\"])\n", + " intended_action = input(\"What would you like to do? Type 'explore' or 'examine'?\").strip()\n", + " if intended_action == \"explore\":\n", + " explore_room(room)\n", + " play_room(room)\n", + " elif intended_action == \"examine\":\n", + " item = (input(\"What would you like to examine?\").strip())\n", + "#here I added the special way to the function ex_piano, that will work the entire new situation with the keyboard and the key\n", + "#to make it work in other rooms it would be basically the same: create a function about the new item and its reactions and linking it here \n", + " if (item == \"piano\"):\n", + " ex_piano(item)\n", + " else: \n", + " examine_item(item)\n", + " else:\n", + " print(\"Not sure what you mean. Type 'explore' or 'examine'.\")\n", + " play_room(room)\n", + " linebreak()\n", + "\n", + "#this next function is new. It makes the keyboard in the piano works and makes you find the key only if you play the piano and you haven't already picked the key\n", + "\n", + "def ex_piano(piano):\n", + " room = game_state[\"current_room\"]\n", + " print(\"The piano looks pretty unused due to the amount of dust.\")\n", + " decission = input(\"Do you want to play it? yes/no \\n\").strip()\n", + " if decission == \"no\":\n", + " print(\"You leave the piano alone\")\n", + " elif decission == \"yes\" and key_a not in game_state[\"keys_collected\"]:\n", + " print(\"Although you cannot play any instrument, you notice there's something wrong\")\n", + " print(\"Stuck under a keyboard key, you find a rusty metal key. \")\n", + " game_state[\"keys_collected\"].append(key_a)\n", + " elif decission == \"yes\" and key_a in game_state[\"keys_collected\"]:\n", + " print(\"You already have the key, there's nothing else\")\n", + " play_room(room)\n", + " \n", + " \n", + "def explore_room(room):\n", + " \n", + " items = [i[\"name\"] for i in object_relations[room[\"name\"]]]\n", + " print(\"You explore the room. This is \" + room[\"name\"] + \". You find \" + \", \".join(items))\n", + "\n", + "def get_next_room_of_door(door, current_room):\n", + " \n", + " connected_rooms = object_relations[door[\"name\"]]\n", + " for room in connected_rooms:\n", + " if(not current_room == room):\n", + " return room\n", + "\n", + "def examine_item(item_name):\n", + " \n", + " current_room = game_state[\"current_room\"]\n", + " next_room = \"\"\n", + " output = None\n", + " \n", + " for item in object_relations[current_room[\"name\"]]:\n", + " if(item[\"name\"] == item_name):\n", + " output = \"You examine \" + item_name + \". \"\n", + " if(item[\"type\"] == \"door\"):\n", + " have_key = False\n", + " for key in game_state[\"keys_collected\"]:\n", + " if(key[\"target\"] == item):\n", + " have_key = True\n", + " if(have_key):\n", + " output += \"You unlock it with a key you have.\"\n", + " next_room = get_next_room_of_door(item, current_room)\n", + " else:\n", + " output += \"It is locked but you don't have the key.\"\n", + " else:\n", + " if(item[\"name\"] in object_relations and len(object_relations[item[\"name\"]])>0):\n", + " item_found = object_relations[item[\"name\"]].pop()\n", + " game_state[\"keys_collected\"].append(item_found)\n", + " output += \"You find \" + item_found[\"name\"] + \".\"\n", + " else:\n", + " output += \"There isn't anything interesting about it.\"\n", + " print(output)\n", + " break\n", + "\n", + " if(output is None):\n", + " print(\"The item you requested is not found in the current room.\")\n", + " \n", + " if(next_room and input(\"Do you want to go to the next room? Ener 'yes' or 'no'\").strip() == 'yes'):\n", + " play_room(next_room)\n", + " else:\n", + " play_room(current_room)\n", + " \n", + "\n", + " \n", + "\n", + " \n", + "game_state = INIT_GAME_STATE.copy()\n", + "\n", + "start_game()\n" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3 (ipykernel)", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.9.7" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/your-code/challenge-2.ipynb b/your-code/challenge-2.ipynb index 556edce..db472e4 100644 --- a/your-code/challenge-2.ipynb +++ b/your-code/challenge-2.ipynb @@ -72,7 +72,7 @@ }, { "cell_type": "code", - "execution_count": 84, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -97,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": 75, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -157,18 +157,19 @@ }, { "cell_type": "code", - "execution_count": 82, + "execution_count": 6, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "['ironhack is cool', 'i love ironhack', 'i am a student at ironhack']\n" + "['Ironhack is cool.', 'I love Ironhack.', 'I am a student at Ironhack.']\n" ] } ], "source": [ + "# Write your code here\n", "for string in corpus:\n", " string.replace('.', '')\n", " string.lower()\n", @@ -185,7 +186,7 @@ }, { "cell_type": "code", - "execution_count": 83, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -205,11 +206,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack', 'is', 'cool.', 'I', 'love', 'Ironhack.', 'am', 'a', 'student', 'at']\n" + ] + } + ], "source": [ - "# Write your code here\n" + "# Write your code here\n", + "for x in corpus:\n", + " split = x.split(' ')\n", + " for y in split:\n", + " if y not in bag_of_words:\n", + " bag_of_words += [y]\n", + "print(bag_of_words)" ] }, { @@ -239,25 +254,13 @@ }, { "cell_type": "code", - "execution_count": 73, + "execution_count": 20, "metadata": {}, - "outputs": [ - { - "ename": "SyntaxError", - "evalue": "invalid syntax (Temp/ipykernel_18976/1639485605.py, line 4)", - "output_type": "error", - "traceback": [ - "\u001b[1;36m File \u001b[1;32m\"C:\\Users\\benja\\AppData\\Local\\Temp/ipykernel_18976/1639485605.py\"\u001b[1;36m, line \u001b[1;32m4\u001b[0m\n\u001b[1;33m terms in bag_of_words:\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" - ] - } - ], + "outputs": [], "source": [ "term_freq = []\n", "\n", - "for i in corpus:\n", - " terms in bag_of_words:\n", - " count += 1\n", - " term_freq.append(count)\n" + "term_freq = [[doc.split(' ').count(words) for words in bag_of_words] for doc in corpus]" ] }, { @@ -271,10 +274,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[[1, 1, 1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 1, 1, 1, 0, 0, 0, 0], [0, 0, 0, 1, 0, 1, 1, 1, 1, 1]]\n" + ] + } + ], + "source": [ + "print(term_freq)" + ] }, { "cell_type": "markdown", @@ -309,14 +322,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Ironhack', 'cool.', 'I', 'love', 'Ironhack.', 'student']\n", + "[[1, 1, 0, 0, 0, 0], [0, 0, 1, 1, 1, 0], [0, 0, 1, 0, 1, 1]]\n" + ] + } + ], "source": [ "stop_words = ['all', 'six', 'less', 'being', 'indeed', 'over', 'move', 'anyway', 'fifty', 'four', 'not', 'own', 'through', 'yourselves', 'go', 'where', 'mill', 'only', 'find', 'before', 'one', 'whose', 'system', 'how', 'somewhere', 'with', 'thick', 'show', 'had', 'enough', 'should', 'to', 'must', 'whom', 'seeming', 'under', 'ours', 'has', 'might', 'thereafter', 'latterly', 'do', 'them', 'his', 'around', 'than', 'get', 'very', 'de', 'none', 'cannot', 'every', 'whether', 'they', 'front', 'during', 'thus', 'now', 'him', 'nor', 'name', 'several', 'hereafter', 'always', 'who', 'cry', 'whither', 'this', 'someone', 'either', 'each', 'become', 'thereupon', 'sometime', 'side', 'two', 'therein', 'twelve', 'because', 'often', 'ten', 'our', 'eg', 'some', 'back', 'up', 'namely', 'towards', 'are', 'further', 'beyond', 'ourselves', 'yet', 'out', 'even', 'will', 'what', 'still', 'for', 'bottom', 'mine', 'since', 'please', 'forty', 'per', 'its', 'everything', 'behind', 'un', 'above', 'between', 'it', 'neither', 'seemed', 'ever', 'across', 'she', 'somehow', 'be', 'we', 'full', 'never', 'sixty', 'however', 'here', 'otherwise', 'were', 'whereupon', 'nowhere', 'although', 'found', 'alone', 're', 'along', 'fifteen', 'by', 'both', 'about', 'last', 'would', 'anything', 'via', 'many', 'could', 'thence', 'put', 'against', 'keep', 'etc', 'amount', 'became', 'ltd', 'hence', 'onto', 'or', 'con', 'among', 'already', 'co', 'afterwards', 'formerly', 'within', 'seems', 'into', 'others', 'while', 'whatever', 'except', 'down', 'hers', 'everyone', 'done', 'least', 'another', 'whoever', 'moreover', 'couldnt', 'throughout', 'anyhow', 'yourself', 'three', 'from', 'her', 'few', 'together', 'top', 'there', 'due', 'been', 'next', 'anyone', 'eleven', 'much', 'call', 'therefore', 'interest', 'then', 'thru', 'themselves', 'hundred', 'was', 'sincere', 'empty', 'more', 'himself', 'elsewhere', 'mostly', 'on', 'fire', 'am', 'becoming', 'hereby', 'amongst', 'else', 'part', 'everywhere', 'too', 'herself', 'former', 'those', 'he', 'me', 'myself', 'made', 'twenty', 'these', 'bill', 'cant', 'us', 'until', 'besides', 'nevertheless', 'below', 'anywhere', 'nine', 'can', 'of', 'your', 'toward', 'my', 'something', 'and', 'whereafter', 'whenever', 'give', 'almost', 'wherever', 'is', 'describe', 'beforehand', 'herein', 'an', 'as', 'itself', 'at', 'have', 'in', 'seem', 'whence', 'ie', 'any', 'fill', 'again', 'hasnt', 'inc', 'thereby', 'thin', 'no', 'perhaps', 'latter', 'meanwhile', 'when', 'detail', 'same', 'wherein', 'beside', 'also', 'that', 'other', 'take', 'which', 'becomes', 'you', 'if', 'nobody', 'see', 'though', 'may', 'after', 'upon', 'most', 'hereupon', 'eight', 'but', 'serious', 'nothing', 'such', 'why', 'a', 'off', 'whereby', 'third', 'i', 'whole', 'noone', 'sometimes', 'well', 'amoungst', 'yours', 'their', 'rather', 'without', 'so', 'five', 'the', 'first', 'whereas', 'once']\n", "\n", "# Write your code below\n", - "\n" + "\n", + "docs = ['doc1.txt', 'doc2.txt', 'doc3.txt']\n", + "\n", + "corpus = [open(doc).read() for doc in docs]\n", + "\n", + "bag_of_words = []\n", + "\n", + "for x in corpus:\n", + " split = x.split(' ')\n", + " for y in split:\n", + " if (y not in bag_of_words and y not in stop_words):\n", + " bag_of_words += [y]\n", + "print(bag_of_words)\n", + "\n", + "term_freq = []\n", + "\n", + "term_freq = [[doc.split(' ').count(words) for words in bag_of_words] for doc in corpus]\n", + "print(term_freq)\n" ] }, {