From 087538323a2e77ef56bd656c157b387c9acc053b Mon Sep 17 00:00:00 2001 From: SeanStanfield Date: Fri, 6 Oct 2017 15:21:17 +0000 Subject: [PATCH] add classwork to github --- cs-python-loops-challenge.ipynb | 92 +++++++++++++++++++++++++-------- 1 file changed, 71 insertions(+), 21 deletions(-) diff --git a/cs-python-loops-challenge.ipynb b/cs-python-loops-challenge.ipynb index ed55ae9..95e0992 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": 235, "metadata": {}, "outputs": [], "source": [ @@ -76,17 +76,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 239, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "10" + ] + }, + "execution_count": 239, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the funtion\n", - "sumTo(100)" + "sumTo(4)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 246, "metadata": {}, "outputs": [], "source": [ @@ -110,23 +121,36 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 272, "metadata": {}, "outputs": [], "source": [ "def squaresTo(num):\n", " squares = 0\n", - " #add your code with the required loop here\n", - " \n", + " for i in range (1, num+1):\n", + " squares = squares + i**2\n", + " \n", + " \n", "\n", " return squares" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 275, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "338350" + ] + }, + "execution_count": 275, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the funtion\n", "squaresTo(100)" @@ -134,7 +158,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 277, "metadata": {}, "outputs": [], "source": [ @@ -151,23 +175,35 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 278, "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": 279, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "1683" + ] + }, + "execution_count": 279, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#run the function\n", "sumOfFactors(3, 100)" @@ -175,7 +211,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 296, "metadata": {}, "outputs": [], "source": [ @@ -191,14 +227,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 348, "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", + "\n", "\n", " return sum2F\n", " " @@ -206,12 +245,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 349, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "0" + ] + }, + "execution_count": 349, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "#call the function\n", - "sumOfMultiplesOfTwoFactors(3,4,100)" + "sumOfMultiplesOfTwoFactors(3,4,10)" ] }, {