From b83ddccf17cefb959be9ffd449682bb864e38a4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n?= Date: Fri, 31 May 2019 09:48:27 -0500 Subject: [PATCH] Agrego ejemplo de iteraciones con la estructura for-else de Python que puede ayudar para estos casos. --- PythonIntroductionLML.ipynb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/PythonIntroductionLML.ipynb b/PythonIntroductionLML.ipynb index 8c33f62..b3c51a7 100644 --- a/PythonIntroductionLML.ipynb +++ b/PythonIntroductionLML.ipynb @@ -269,6 +269,22 @@ " print(str(x)+\" es un cubo perfecto\")" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Python tiene una estructura for-else que ayuda para estos casos :)\n", + "x=64\n", + "for ans in range(0,x):\n", + " if ans**3 == x:\n", + " print(str(x)+\" es un cubo perfecto\")\n", + " break\n", + "else:\n", + " print(str(x)+\" no es un cubo perfecto\")" + ] + }, { "cell_type": "code", "execution_count": null, @@ -723,7 +739,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.6.5" + "version": "3.6.7" } }, "nbformat": 4,