Skip to content

Instantly share code, notes, and snippets.

@CaptSpaceBat
Created February 17, 2019 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CaptSpaceBat/9a230682248cb200210a5fff9744637c to your computer and use it in GitHub Desktop.
Save CaptSpaceBat/9a230682248cb200210a5fff9744637c to your computer and use it in GitHub Desktop.
Created on Cognitive Class Labs
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>For Loops </h3> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Use loops to print out the elements in the list <code>A</code>"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n"
]
}
],
"source": [
"A=[1,2,3,4,5]\n",
"for a in A:\n",
" print(a)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<h3 align=center>While Loops</h3> "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Find the value of <code> x </code> that will print out the sequence <code> 1,2,..,10 </code>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n",
"6\n",
"7\n",
"8\n",
"9\n",
"10\n"
]
}
],
"source": [
"x=11\n",
"y=1\n",
"while(y< x):\n",
" print(y)\n",
" y=y+1"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<hr>\n",
"<small>Copyright &copy; 2018 IBM Cognitive Class. This notebook and its source code are released under the terms of the [MIT License](https://cognitiveclass.ai/mit-license/).</small>"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.6.8"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment