diff --git a/cs-python-loops-challenge.ipynb b/cs-python-loops-challenge.ipynb index ed55ae9..d66b619 100644 --- a/cs-python-loops-challenge.ipynb +++ b/cs-python-loops-challenge.ipynb @@ -42,7 +42,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -76,9 +76,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "5050" + ] + }, + "execution_count": 13, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the funtion\n", "sumTo(100)" @@ -86,7 +97,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], "source": [ @@ -110,23 +121,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 25, "metadata": {}, "outputs": [], "source": [ "def squaresTo(num):\n", - " squares = 0\n", + " squares=0\n", " #add your code with the required loop here\n", + " for i in range(1,num+1):\n", + " squares+=i**2\n", " \n", - "\n", " return squares" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 164, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "338350" + ] + }, + "execution_count": 164, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the funtion\n", "squaresTo(100)" @@ -134,7 +157,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 111, "metadata": {}, "outputs": [], "source": [ @@ -151,23 +174,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 154, "metadata": {}, "outputs": [], "source": [ "def sumOfFactors(factor, num):\n", " sumF=0\n", " # add the loop here\n", - " \n", + " for i in range(0,num,factor):\n", + " sumF+=i\n", " \n", " return sumF" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 174, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1683" + ] + }, + "execution_count": 174, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the function\n", "sumOfFactors(3, 100)" @@ -175,7 +210,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 163, "metadata": {}, "outputs": [], "source": [ @@ -191,14 +226,15 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 165, "metadata": {}, "outputs": [], "source": [ "def sumOfMultiplesOfTwoFactors(f1,f2,num):\n", " sum2F = 0\n", " #add your code with loop here\n", - " \n", + " for i in range(0,num+1,f1*f2):\n", + " sum2F+=i\n", "\n", " return sum2F\n", " " @@ -206,17 +242,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 170, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "120" + ] + }, + "execution_count": 170, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#call the function\n", - "sumOfMultiplesOfTwoFactors(3,4,100)" + "sumOfMultiplesOfTwoFactors(3,4,50)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 171, "metadata": {}, "outputs": [], "source": [ @@ -225,7 +272,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 172, "metadata": {}, "outputs": [], "source": [ @@ -253,6 +300,10 @@ " isPrime = True\n", " \n", " #write your code using a loop to test whether a number is a prime\n", + " for i in range(2, 10):\n", + " if (num % i == 0):\n", + " isPrime = False\n", + "\n", " #hint: when is a number NOT a prime??\n", " \n", " return isPrime\n" @@ -270,7 +321,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 177, "metadata": {}, "outputs": [], "source": [ @@ -280,7 +331,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 178, "metadata": {}, "outputs": [], "source": [ @@ -289,7 +340,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 179, "metadata": {}, "outputs": [], "source": [