Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 71 additions & 21 deletions cs-python-loops-challenge.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 235,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -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": [
Expand All @@ -110,31 +121,44 @@
},
{
"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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 277,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -151,31 +175,43 @@
},
{
"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)"
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 296,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -191,27 +227,41 @@
},
{
"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",
" "
]
},
{
"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)"
]
},
{
Expand Down