"Loops in Python are used to execute a series of code or statements back to back until a specific condition is true or satisfied in a list, tuple, or set. Once the condition is recognized as false, the upcoming line of code is stopped. There are a few different types of loops. \n"
]
},
{
"cell_type": "markdown",
"id": "cec184aa",
"metadata": {},
"source": [
"# Types of Loops"
]
},
{
"cell_type": "markdown",
"id": "f14394ce",
"metadata": {},
"source": [
"A while loop is used to evaluate a condition before processing a body of code inside of a loop. If a statement is false, the body of the code will not be executed. While, if it is found true only the body of the loop is executed.\n",
"A do-while loop or exit-controlled loop allows for a condition to always be executed after the body of a loop.\n"
"Input \u001b[0;32mIn [5]\u001b[0m, in \u001b[0;36m<cell line: 3>\u001b[0;34m()\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;66;03m#Put Your Answer Here\u001b[39;00m\n\u001b[1;32m 2\u001b[0m num\u001b[38;5;241m=\u001b[39m\u001b[38;5;28mint\u001b[39m(\u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEnter any number\u001b[39m\u001b[38;5;124m\"\u001b[39m))\n\u001b[0;32m----> 3\u001b[0m answer\u001b[38;5;241m=\u001b[39m\u001b[43mfalse\u001b[49m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m num\u001b[38;5;241m==\u001b[39m\u001b[38;5;241m1\u001b[39m \u001b[38;5;129;01mor\u001b[39;00m num\u001b[38;5;241m==\u001b[39m\u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 5\u001b[0m answer\u001b[38;5;241m=\u001b[39mtrue\n",
"\u001b[0;31mNameError\u001b[0m: name 'false' is not defined"
]
}
],
"source": [
"#Put Your Answer Here\n",
"num=int(input(\"Enter any number\"))\n",
"answer=false\n",
"if num==1 or num==0:\n",
" answer=true\n",
"for i in range(2,num):\n",
" if num%i==0:\n",
" answer=true\n",
"if answer==true:\n",
" print(\"Number is not prime\")\n",
"else:\n",
" print(\"Number is prime\")\n",
"\n",
"Assert(prime(11))\n",
"Assert(prime(3))"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1474fb12",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:b64fb56b tags:
# Loops
%% Cell type:markdown id:a4435deb tags:
# Short/Long Title: Loops
%% Cell type:markdown id:eb8f94bb tags:
# Description:
%% Cell type:markdown id:4c94faf5 tags:
Loops in Python are used to execute a series of code or statements back to back until a specific condition is true or satisfied in a list, tuple, or set. Once the condition is recognized as false, the upcoming line of code is stopped. There are a few different types of loops.
%% Cell type:markdown id:cec184aa tags:
# Types of Loops
%% Cell type:markdown id:f14394ce tags:
A while loop is used to evaluate a condition before processing a body of code inside of a loop. If a statement is false, the body of the code will not be executed. While, if it is found true only the body of the loop is executed.
A do-while loop or exit-controlled loop allows for a condition to always be executed after the body of a loop.
"Whitespaces or indedentation act as the spaces at the very start or inside of a code for enhanced readibility in Python. It is used to designate a block of code inside of a program. Any code without indentation or white space is attached to a specific source file. Whitespaces tend to be sensitive due to their ability to completely effect the possibilities of an output of a code or interpretation of a statement ultimately causing an error to pop up.\n",
"\n",
"It is important to understand, whitespace must always be consistant throughout code. So if a programmer starts with 5 spaces, 5 space must be used throughout the remainder of the block of code or else a syntax error will not allow the code to be ran."
"Sentence = \"What time does lunch begin at Shaw?\"\n",
" \n",
"for i in Sentence:\n",
" \n",
" # determines if whitespace is found in code\n",
" if i in string.whitespace:\n",
" \n",
" # Prints the number of whitespace values and its characters\n",
" print(\"printable Value is: \" + i)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "351205d1",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
%% Cell type:markdown id:950c4fef tags:
# Whitespace Sensitivity
%% Cell type:markdown id:019e60ef tags:
Short Title: Indentation
%% Cell type:markdown id:c61cba51 tags:
# Description
%% Cell type:markdown id:55abe61f tags:
Whitespaces or indedentation act as the spaces at the very start or inside of a code for enhanced readibility in Python. It is used to designate a block of code inside of a program. Any code without indentation or white space is attached to a specific source file. Whitespaces tend to be sensitive due to their ability to completely effect the possibilities of an output of a code or interpretation of a statement ultimately causing an error to pop up.
It is important to understand, whitespace must always be consistant throughout code. So if a programmer starts with 5 spaces, 5 space must be used throughout the remainder of the block of code or else a syntax error will not allow the code to be ran.