From 7021fb0714b34cc67f273dbcef8295e0806a5af0 Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Tue, 13 Jan 2026 17:28:07 +0100 Subject: [PATCH 1/3] update-lab-extra --- lab-python-flow-control.ipynb | 90 +++++++++++++++++++++++++++++++---- 1 file changed, 82 insertions(+), 8 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 7905339..5ff6dee 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -77,7 +77,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, + "id": "119ba7a3", + "metadata": {}, + "outputs": [], + "source": [ + "import random" + ] + }, + { + "cell_type": "code", + "execution_count": 9, "id": "499552c8-9e30-46e1-a706-4ac5dc64670e", "metadata": {}, "outputs": [], @@ -93,12 +103,20 @@ " \"\"\"\n", " print(\"You encounter a ghost!\")\n", " \n", - " # your code goes here" + " # your code goes here\n", + " event = ramdon.randint(1,10)\n", + " if event < 5:\n", + " print(\"Ypu defeated the ghost!\")\n", + " return True\n", + " else:\n", + " print(\"You lost the battle...\")\n", + " return False\n", + " " ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "id": "d3e4076b-48cc-41ac-95ad-891743e775f5", "metadata": {}, "outputs": [], @@ -130,7 +148,49 @@ "\n", " \"\"\"\n", " \n", - " # your code goes here" + " # your code goes here\n", + " health = 0 \n", + " items_adventurer = []\n", + "\n", + " while health > 0:\n", + " choice = input(\"Choose between two paths: (left or right)\").lower()\n", + " \n", + " if choice == 'left':\n", + " event1 = random.choice([\"potion\", \"trap\"])\n", + "\n", + " if event1 == 'potion':\n", + " print(\"You found a potion!!!\")\n", + " items_adventurer.append('potion')\n", + " else:\n", + " print(\"You feel into a trap!!!, You lose 2 points of health =()\")\n", + " health -=2\n", + "\n", + " elif choice == 'right':\n", + " event2 = encounter_ghost()\n", + "\n", + " if event2:\n", + " print(\"You defeated the ghost and found a key!\")\n", + " items_adventurer.append(\"key\")\n", + " else:\n", + " print(\"The ghost won!, You lose 2 points od health =()\")\n", + " health -= 2\n", + "\n", + " else:\n", + " print(\"Invalid choice. Try again\")\n", + " continue\n", + "\n", + " #Health\n", + " if health <= 0:\n", + " print(\"Game over, you lost all your health points.\")\n", + " return \n", + " \n", + " #The player has the key\n", + " if \"key\" in items_adventurer:\n", + " print(\"You unlocked the door and found the Treasure! Congratulations!\")\n", + " return \n", + " else:\n", + " print(\"You don't have the key. Try again from the beginning\")\n", + "\n" ] }, { @@ -143,10 +203,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 11, "id": "f238dc90-0be2-4d8c-93e9-30a1dc8a5b72", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to the Haunted Mansion!\n" + ] + } + ], "source": [ "run_mansion()" ] @@ -158,11 +226,17 @@ "source": [ "This should print the game's narrative and prompt the user to make choices and fight ghosts. The game ends when the adventurer finds the key or loses all their health points. " ] + }, + { + "cell_type": "markdown", + "id": "96e0af2d", + "metadata": {}, + "source": [] } ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -176,7 +250,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.10.2" } }, "nbformat": 4, From 1c3bb9c0ee9cefd28e5db299c445df0c224fb533 Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Tue, 13 Jan 2026 17:32:51 +0100 Subject: [PATCH 2/3] update-feedback --- lab-python-flow-control.ipynb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 5ff6dee..3c21c55 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -87,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": null, "id": "499552c8-9e30-46e1-a706-4ac5dc64670e", "metadata": {}, "outputs": [], @@ -105,8 +105,8 @@ " \n", " # your code goes here\n", " event = ramdon.randint(1,10)\n", - " if event < 5:\n", - " print(\"Ypu defeated the ghost!\")\n", + " if event <= 5:\n", + " print(\"You defeated the ghost!\")\n", " return True\n", " else:\n", " print(\"You lost the battle...\")\n", @@ -116,7 +116,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "d3e4076b-48cc-41ac-95ad-891743e775f5", "metadata": {}, "outputs": [], @@ -149,7 +149,7 @@ " \"\"\"\n", " \n", " # your code goes here\n", - " health = 0 \n", + " health = 10 \n", " items_adventurer = []\n", "\n", " while health > 0:\n", @@ -159,10 +159,10 @@ " event1 = random.choice([\"potion\", \"trap\"])\n", "\n", " if event1 == 'potion':\n", - " print(\"You found a potion!!!\")\n", + " print(\"You found a potion!\")\n", " items_adventurer.append('potion')\n", " else:\n", - " print(\"You feel into a trap!!!, You lose 2 points of health =()\")\n", + " print(\"You feel into a trap!, You lose 2 points of health)\")\n", " health -=2\n", "\n", " elif choice == 'right':\n", @@ -172,7 +172,7 @@ " print(\"You defeated the ghost and found a key!\")\n", " items_adventurer.append(\"key\")\n", " else:\n", - " print(\"The ghost won!, You lose 2 points od health =()\")\n", + " print(\"The ghost won!, You lose 2 points of health =()\")\n", " health -= 2\n", "\n", " else:\n", From ce17341685927c14e796b1d485e6b5cb88a122af Mon Sep 17 00:00:00 2001 From: MonicaFernandezM Date: Tue, 13 Jan 2026 17:34:36 +0100 Subject: [PATCH 3/3] update-errors --- lab-python-flow-control.ipynb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 3c21c55..86a162f 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -77,7 +77,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 13, "id": "119ba7a3", "metadata": {}, "outputs": [], @@ -104,7 +104,7 @@ " print(\"You encounter a ghost!\")\n", " \n", " # your code goes here\n", - " event = ramdon.randint(1,10)\n", + " event = random.randint(1,10)\n", " if event <= 5:\n", " print(\"You defeated the ghost!\")\n", " return True\n",