diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..81964c2 Binary files /dev/null and b/.DS_Store differ diff --git a/lab-python-flow-control.ipynb b/lab-python-flow-control.ipynb index 7905339..43c5af1 100644 --- a/lab-python-flow-control.ipynb +++ b/lab-python-flow-control.ipynb @@ -98,7 +98,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "id": "d3e4076b-48cc-41ac-95ad-891743e775f5", "metadata": {}, "outputs": [], @@ -130,7 +130,70 @@ "\n", " \"\"\"\n", " \n", - " # your code goes here" + " # your code goes here\n", + " import random\n", + "\n", + "def encounter_ghost():\n", + " \"\"\"\n", + " Simula el encuentro con un fantasma.\n", + " Devuelve True si el aventurero gana, False si pierde.\n", + " \"\"\"\n", + " print(\"πŸ‘» You encounter a ghost!\")\n", + " roll = random.randint(1, 10) # nΓΊmero aleatorio entre 1 y 10\n", + "\n", + " if roll <= 5:\n", + " print(\"βœ… You defeated the ghost!\")\n", + " return True\n", + " else:\n", + " print(\"❌ You lost the battle...\")\n", + " return False\n", + "\n", + "\n", + "def run_mansion():\n", + " \"\"\"\n", + " Juego principal: Haunted Mansion.\n", + " El aventurero empieza con 10 puntos de vida y sin objetos.\n", + " \"\"\"\n", + " health = 10\n", + " items = []\n", + "\n", + " print(\"🏰 Welcome to the Haunted Mansion!\")\n", + " print(f\"You start with {health} health points.\")\n", + "\n", + " while health > 0:\n", + " choice = input(\"\\nDo you go 'left' or 'right'? \").lower()\n", + "\n", + " if choice == \"left\":\n", + " # Evento aleatorio: pociΓ³n o trampa\n", + " if random.choice([True, False]):\n", + " print(\"🍡 You found a potion! Health +2.\")\n", + " health += 2\n", + " items.append(\"potion\")\n", + " else:\n", + " print(\"⚠️ You fell into a trap! Health -2.\")\n", + " health -= 2\n", + "\n", + " elif choice == \"right\":\n", + " won = encounter_ghost()\n", + " if won:\n", + " print(\"πŸ— You found a key!\")\n", + " items.append(\"key\")\n", + " else:\n", + " health -= 2\n", + " print(f\"πŸ’” You lost 2 health. Remaining: {health}\")\n", + "\n", + " else:\n", + " print(\"❓ Invalid choice, try again.\")\n", + " continue\n", + "\n", + " # Condiciones de fin\n", + " if health <= 0:\n", + " print(\"☠️ Game over, you lost all your health points.\")\n", + " break\n", + "\n", + " if \"key\" in items:\n", + " print(\"πŸŽ‰ You unlocked the door and found the Treasure! Congratulations!\")\n", + " break\n" ] }, { @@ -143,10 +206,27 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "id": "f238dc90-0be2-4d8c-93e9-30a1dc8a5b72", "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "🏰 Welcome to the Haunted Mansion!\n", + "You start with 10 health points.\n", + "🍡 You found a potion! Health +2.\n", + "❓ Invalid choice, try again.\n", + "🍡 You found a potion! Health +2.\n", + "⚠️ You fell into a trap! Health -2.\n", + "πŸ‘» You encounter a ghost!\n", + "βœ… You defeated the ghost!\n", + "πŸ— You found a key!\n", + "πŸŽ‰ You unlocked the door and found the Treasure! Congratulations!\n" + ] + } + ], "source": [ "run_mansion()" ] @@ -162,7 +242,7 @@ ], "metadata": { "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "base", "language": "python", "name": "python3" }, @@ -176,7 +256,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,