Skip to content

Commit ef67bf0

Browse files
authored
Add files via upload
1 parent 4c850ff commit ef67bf0

File tree

1 file changed

+355
-0
lines changed

1 file changed

+355
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,355 @@
1+
{
2+
"nbformat": 4,
3+
"nbformat_minor": 0,
4+
"metadata": {
5+
"colab": {
6+
"name": "Flow_Control_in_Python.ipynb",
7+
"version": "0.3.2",
8+
"provenance": []
9+
},
10+
"kernelspec": {
11+
"name": "python3",
12+
"display_name": "Python 3"
13+
}
14+
},
15+
"cells": [
16+
{
17+
"cell_type": "markdown",
18+
"metadata": {
19+
"id": "iQUE1NgyKiZZ",
20+
"colab_type": "text"
21+
},
22+
"source": [
23+
"## If Statement\n",
24+
"\n",
25+
"---\n",
26+
"\n",
27+
"The Python compound statement ’if’ lets you conditionally execute blocks of statements.\n",
28+
"\n"
29+
]
30+
},
31+
{
32+
"cell_type": "code",
33+
"metadata": {
34+
"id": "SHADwzUfKefZ",
35+
"colab_type": "code",
36+
"colab": {
37+
"base_uri": "https://localhost:8080/",
38+
"height": 51
39+
},
40+
"outputId": "cab43e7d-4f5f-4772-be36-b86ce0a97fcc"
41+
},
42+
"source": [
43+
"password = input(\"Enter Your password\")\n",
44+
"\n",
45+
"if password == \"suneel\":\n",
46+
" print('Login successful.')\n",
47+
"else:\n",
48+
" print('Login failed. Incorrect password.')"
49+
],
50+
"execution_count": 12,
51+
"outputs": [
52+
{
53+
"output_type": "stream",
54+
"text": [
55+
"Enter Your passwordsuneel\n",
56+
"Login successful.\n"
57+
],
58+
"name": "stdout"
59+
}
60+
]
61+
},
62+
{
63+
"cell_type": "markdown",
64+
"metadata": {
65+
"id": "316G2IFTLs8c",
66+
"colab_type": "text"
67+
},
68+
"source": [
69+
"## For Statement:\n",
70+
"\n",
71+
"---\n",
72+
"\n",
73+
"The for statement supports repeated execution of a statement or block of statements that is controlled by an iterable expression."
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"metadata": {
79+
"id": "_49bDiS-KsQR",
80+
"colab_type": "code",
81+
"colab": {
82+
"base_uri": "https://localhost:8080/",
83+
"height": 204
84+
},
85+
"outputId": "0cbeddbe-74ae-4da0-83de-5684d2eafdf3"
86+
},
87+
"source": [
88+
"# Let us now look at a sample program in Python to demonstrate the For statement.\n",
89+
"\n",
90+
"travelling = input(\"Are you travelling? Yes or No:\")\n",
91+
"while travelling == 'yes':\n",
92+
" num = int(input(\"Enter the number of people travelling:\"))\n",
93+
" for num in range(1,num+1):\n",
94+
" name = input(\"Enter Details Name:\")\n",
95+
" age = input(\"Age:\")\n",
96+
" sex = input(\"Male or Female:\")\n",
97+
" print(\"Details Stored\",name)\n",
98+
" print(age)\n",
99+
" print(sex)\n",
100+
" print(\"Thank you!\")\n",
101+
" travelling = input(\"Are you travelling? Yes or No:\")\n",
102+
"print(\"Please come back again.\")"
103+
],
104+
"execution_count": 7,
105+
"outputs": [
106+
{
107+
"output_type": "stream",
108+
"text": [
109+
"Are you travelling? Yes or No:yes\n",
110+
"Enter the number of people travelling:1\n",
111+
"Enter Details Name:Suneel Patel\n",
112+
"Age:33\n",
113+
"Male or Female:Male\n",
114+
"Details Stored Suneel Patel\n",
115+
"33\n",
116+
"Male\n",
117+
"Thank you!\n",
118+
"Are you travelling? Yes or No:no\n",
119+
"Please come back again.\n"
120+
],
121+
"name": "stdout"
122+
}
123+
]
124+
},
125+
{
126+
"cell_type": "markdown",
127+
"metadata": {
128+
"id": "jz3HnD2MM6r8",
129+
"colab_type": "text"
130+
},
131+
"source": [
132+
"## While Statement: \n",
133+
"\n",
134+
"---\n",
135+
"\n",
136+
"The while statement in Python programming supports repeated execution of a statement or block of statements that is controlled by a conditional expression."
137+
]
138+
},
139+
{
140+
"cell_type": "code",
141+
"metadata": {
142+
"id": "U-zf1DJXMMgI",
143+
"colab_type": "code",
144+
"colab": {
145+
"base_uri": "https://localhost:8080/",
146+
"height": 221
147+
},
148+
"outputId": "da866ff3-5ea6-47cd-c68f-2ca8af041d05"
149+
},
150+
"source": [
151+
"# Let us now look at a sample program in Python to demonstrate the While statement.\n",
152+
"count = 0\n",
153+
"print('Printing numbers from 0 to 9')\n",
154+
"while (count<10):\n",
155+
" print('The count is ',count)\n",
156+
" count = count+1\n",
157+
"print('Good Bye')\n"
158+
],
159+
"execution_count": 13,
160+
"outputs": [
161+
{
162+
"output_type": "stream",
163+
"text": [
164+
"Printing numbers from 0 to 9\n",
165+
"The count is 0\n",
166+
"The count is 1\n",
167+
"The count is 2\n",
168+
"The count is 3\n",
169+
"The count is 4\n",
170+
"The count is 5\n",
171+
"The count is 6\n",
172+
"The count is 7\n",
173+
"The count is 8\n",
174+
"The count is 9\n",
175+
"Good Bye\n"
176+
],
177+
"name": "stdout"
178+
}
179+
]
180+
},
181+
{
182+
"cell_type": "markdown",
183+
"metadata": {
184+
"id": "GycaNZgCNO22",
185+
"colab_type": "text"
186+
},
187+
"source": [
188+
"## Break Statement: \n",
189+
"\n",
190+
"---\n",
191+
"The break statement is allowed only inside a loop body. When break executes, the loop terminates. If a loop is nested inside other loops, break terminates only the innermost nested loop."
192+
]
193+
},
194+
{
195+
"cell_type": "code",
196+
"metadata": {
197+
"id": "i4noOCdcNKkO",
198+
"colab_type": "code",
199+
"colab": {
200+
"base_uri": "https://localhost:8080/",
201+
"height": 340
202+
},
203+
"outputId": "604383dc-33ad-4d25-e1c3-e7688897b3e4"
204+
},
205+
"source": [
206+
"for letter in 'The Quick Brown Fox. Jumps, Over The Lazy Dog':\n",
207+
" if letter == '.':\n",
208+
" break\n",
209+
" print ('Current Letter :', letter)"
210+
],
211+
"execution_count": 14,
212+
"outputs": [
213+
{
214+
"output_type": "stream",
215+
"text": [
216+
"Current Letter : T\n",
217+
"Current Letter : h\n",
218+
"Current Letter : e\n",
219+
"Current Letter : \n",
220+
"Current Letter : Q\n",
221+
"Current Letter : u\n",
222+
"Current Letter : i\n",
223+
"Current Letter : c\n",
224+
"Current Letter : k\n",
225+
"Current Letter : \n",
226+
"Current Letter : B\n",
227+
"Current Letter : r\n",
228+
"Current Letter : o\n",
229+
"Current Letter : w\n",
230+
"Current Letter : n\n",
231+
"Current Letter : \n",
232+
"Current Letter : F\n",
233+
"Current Letter : o\n",
234+
"Current Letter : x\n"
235+
],
236+
"name": "stdout"
237+
}
238+
]
239+
},
240+
{
241+
"cell_type": "markdown",
242+
"metadata": {
243+
"id": "nYBMT0opNii0",
244+
"colab_type": "text"
245+
},
246+
"source": [
247+
"## Continue Statement: \n",
248+
"\n",
249+
"---\n",
250+
"\n",
251+
"The continue statement is allowed only inside a loop body. When continue executes, the current iteration of the loop body terminates, and execution continues with the next iteration of the loop."
252+
]
253+
},
254+
{
255+
"cell_type": "code",
256+
"metadata": {
257+
"id": "T2EXi5UlNlhJ",
258+
"colab_type": "code",
259+
"colab": {
260+
"base_uri": "https://localhost:8080/",
261+
"height": 204
262+
},
263+
"outputId": "f8821cf5-1542-4e5a-8ebe-6c10c6877e36"
264+
},
265+
"source": [
266+
"# Let us now look at a sample program in Python to demonstrate the Continue statement.\n",
267+
"for num in range(10, 21):\n",
268+
" if num % 5 == 0:\n",
269+
" print (\"Found a multiple of 5\")\n",
270+
" pass\n",
271+
" num = num + 1\n",
272+
" continue\n",
273+
" print (\"Found number: \", num)"
274+
],
275+
"execution_count": 15,
276+
"outputs": [
277+
{
278+
"output_type": "stream",
279+
"text": [
280+
"Found a multiple of 5\n",
281+
"Found number: 11\n",
282+
"Found number: 12\n",
283+
"Found number: 13\n",
284+
"Found number: 14\n",
285+
"Found a multiple of 5\n",
286+
"Found number: 16\n",
287+
"Found number: 17\n",
288+
"Found number: 18\n",
289+
"Found number: 19\n",
290+
"Found a multiple of 5\n"
291+
],
292+
"name": "stdout"
293+
}
294+
]
295+
},
296+
{
297+
"cell_type": "markdown",
298+
"metadata": {
299+
"id": "E-0VnJwjOCnM",
300+
"colab_type": "text"
301+
},
302+
"source": [
303+
"## Pass Statement:\n",
304+
"\n",
305+
"---\n",
306+
"\n",
307+
"The pass statement, which performs no action, can be used as a placeholder when a statement is syntactically required but you have nothing specific to do."
308+
]
309+
},
310+
{
311+
"cell_type": "code",
312+
"metadata": {
313+
"id": "11MljIF6NwZx",
314+
"colab_type": "code",
315+
"colab": {
316+
"base_uri": "https://localhost:8080/",
317+
"height": 255
318+
},
319+
"outputId": "3ce243e1-3cfc-406c-9bce-8d1ee794e921"
320+
},
321+
"source": [
322+
"# Now let us look at a sample program in Python to demonstrate the Pass statement.\n",
323+
"for num in range(10, 21):\n",
324+
" if num % 5 == 0:\n",
325+
" print (\"Found a multiple of 5: \")\n",
326+
" pass\n",
327+
" num++1\n",
328+
" print(\"Found number: \", num)"
329+
],
330+
"execution_count": 20,
331+
"outputs": [
332+
{
333+
"output_type": "stream",
334+
"text": [
335+
"Found a multiple of 5: \n",
336+
"Found number: 10\n",
337+
"Found number: 11\n",
338+
"Found number: 12\n",
339+
"Found number: 13\n",
340+
"Found number: 14\n",
341+
"Found a multiple of 5: \n",
342+
"Found number: 15\n",
343+
"Found number: 16\n",
344+
"Found number: 17\n",
345+
"Found number: 18\n",
346+
"Found number: 19\n",
347+
"Found a multiple of 5: \n",
348+
"Found number: 20\n"
349+
],
350+
"name": "stdout"
351+
}
352+
]
353+
}
354+
]
355+
}

0 commit comments

Comments
 (0)