Skip to content

Commit 1889b86

Browse files
authored
updates with more examples and exercises
1 parent e81c718 commit 1889b86

8 files changed

+8311
-0
lines changed
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"<small><small><i>\n",
8+
"All the IPython Notebooks in **Python Flow Control Statements** lecture series by Dr. Milaan Parmar are available @ **[GitHub](https://github.com/milaan9/03_Python_Flow_Control)**\n",
9+
"</i></small></small>"
10+
]
11+
},
12+
{
13+
"cell_type": "markdown",
14+
"metadata": {},
15+
"source": [
16+
"# Python Flow-Control (Decision-Making) Statements\n",
17+
"\n",
18+
"In Python programming, decision-making statements are those that **help in deciding the flow of the program**. \n",
19+
"\n",
20+
"For example, at times, you might want to execute a block of code only if a particular condition is satisfied. Well, in this case, decision-making statement will be of great help. Let us consider an example to understand this better.\n",
21+
"\n",
22+
"Decision making is required when we want to execute a code only if a certain condition is satisfied.\n",
23+
"\n",
24+
"The key thing to note about Python's control flow statements and program structure is that it uses **`_indentation_`** to mark blocks. Hence the amount of white space (space or tab characters) at the start of a line is very important. This generally helps to make code more readable but can catch out new users of python."
25+
]
26+
},
27+
{
28+
"cell_type": "markdown",
29+
"metadata": {},
30+
"source": [
31+
"* Suppose you are given a number and are asked to check if it is an even number or not. How would you do it?\n",
32+
"\n",
33+
"> The first thought that would pop up your mind is this - **\"If the number is divisible by 2, then it is an even number, else it is an odd number\"**. That's absolutely the right logic. But when this has to be coded, you will need the help of decision-making statements. To understand this, let's now look at how they function."
34+
]
35+
},
36+
{
37+
"cell_type": "markdown",
38+
"metadata": {},
39+
"source": [
40+
"## Control Flow Statements\n",
41+
"\n",
42+
"The flow control statements are divided into **three** categories:\n",
43+
"\n",
44+
"1. **Conditional statements**\n",
45+
"2. **Iterative statements**\n",
46+
"3. **Transfer/Control statements**\n",
47+
"\n",
48+
"<div>\n",
49+
"<img src=\"img/fcs.png\" width=\"500\"/>\n",
50+
"</div>"
51+
]
52+
},
53+
{
54+
"cell_type": "markdown",
55+
"metadata": {},
56+
"source": [
57+
"## Conditional statements\n",
58+
"\n",
59+
"In Python, condition statements act depending on whether a given condition is true or false. You can execute different blocks of codes depending on the outcome of a condition. Condition statements always evaluate to either **`True`** or **`False`**.\n",
60+
"\n",
61+
"There are **four** types of conditional statements:\n",
62+
"\n",
63+
"1. **[if](https://github.com/milaan9/03_Python_Flow_Control/blob/main/001_Python_if_statement.ipynb)**\n",
64+
"2. **[if-else](https://github.com/milaan9/03_Python_Flow_Control/blob/main/002_Python_if_else_statement.ipynb)**\n",
65+
"3. **[if-elif-else](https://github.com/milaan9/03_Python_Flow_Control/blob/main/003_Python_if_elif_else_statement%20.ipynb)**\n",
66+
"4. **[nested-if](https://github.com/milaan9/03_Python_Flow_Control/blob/main/004_Python_Nested_if_statement.ipynb)**"
67+
]
68+
},
69+
{
70+
"cell_type": "markdown",
71+
"metadata": {},
72+
"source": [
73+
"## Iterative statements\n",
74+
"\n",
75+
"In Python, iterative statements allow us to execute a block of code repeatedly as long as the condition is **`True`**. We also call it a loop statements.\n",
76+
"\n",
77+
"Python provides us the following **two** loop statement to perform some actions repeatedly\n",
78+
"\n",
79+
"1. **[for loop](https://github.com/milaan9/03_Python_Flow_Control/blob/main/005_Python_for_Loop.ipynb)**\n",
80+
"2. **[while loop](https://github.com/milaan9/03_Python_Flow_Control/blob/main/006_Python_while_Loop.ipynb)**"
81+
]
82+
},
83+
{
84+
"cell_type": "markdown",
85+
"metadata": {},
86+
"source": [
87+
"## Transfer statements\n",
88+
"\n",
89+
"In Python, transfer statements are used to alter the program’s way of execution in a certain manner. For this purpose, we use **three** types of transfer statements.\n",
90+
"\n",
91+
"1. **[break statement](https://github.com/milaan9/03_Python_Flow_Control/blob/main/007_Python_break_continue_pass_statements.ipynb)**\n",
92+
"2. **[continue statement](https://github.com/milaan9/03_Python_Flow_Control/blob/main/007_Python_break_continue_pass_statements.ipynb)**\n",
93+
"3. **[pass statements](https://github.com/milaan9/03_Python_Flow_Control/blob/main/007_Python_break_continue_pass_statements.ipynb)**"
94+
]
95+
},
96+
{
97+
"cell_type": "code",
98+
"execution_count": null,
99+
"metadata": {},
100+
"outputs": [],
101+
"source": []
102+
}
103+
],
104+
"metadata": {
105+
"hide_input": false,
106+
"kernelspec": {
107+
"display_name": "Python 3",
108+
"language": "python",
109+
"name": "python3"
110+
},
111+
"language_info": {
112+
"codemirror_mode": {
113+
"name": "ipython",
114+
"version": 3
115+
},
116+
"file_extension": ".py",
117+
"mimetype": "text/x-python",
118+
"name": "python",
119+
"nbconvert_exporter": "python",
120+
"pygments_lexer": "ipython3",
121+
"version": "3.8.8"
122+
},
123+
"toc": {
124+
"base_numbering": 1,
125+
"nav_menu": {},
126+
"number_sections": true,
127+
"sideBar": true,
128+
"skip_h1_title": false,
129+
"title_cell": "Table of Contents",
130+
"title_sidebar": "Contents",
131+
"toc_cell": false,
132+
"toc_position": {},
133+
"toc_section_display": true,
134+
"toc_window_display": false
135+
},
136+
"varInspector": {
137+
"cols": {
138+
"lenName": 16,
139+
"lenType": 16,
140+
"lenVar": 40
141+
},
142+
"kernels_config": {
143+
"python": {
144+
"delete_cmd_postfix": "",
145+
"delete_cmd_prefix": "del ",
146+
"library": "var_list.py",
147+
"varRefreshCmd": "print(var_dic_list())"
148+
},
149+
"r": {
150+
"delete_cmd_postfix": ") ",
151+
"delete_cmd_prefix": "rm(",
152+
"library": "var_list.r",
153+
"varRefreshCmd": "cat(var_dic_list()) "
154+
}
155+
},
156+
"types_to_exclude": [
157+
"module",
158+
"function",
159+
"builtin_function_or_method",
160+
"instance",
161+
"_Feature"
162+
],
163+
"window_display": false
164+
}
165+
},
166+
"nbformat": 4,
167+
"nbformat_minor": 2
168+
}

0 commit comments

Comments
 (0)