author | anoop |
Sat, 09 Oct 2010 03:56:06 +0530 | |
changeset 261 | c7f0069d698a |
parent 254 | c43677920502 |
child 278 | 461a68dbefb1 |
permissions | -rw-r--r-- |
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
1 |
.. Objectives |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
2 |
.. ---------- |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
3 |
|
254
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
4 |
.. By the end of this tutorial, you will be able to |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
5 |
|
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
6 |
.. 1. use the ``for`` loop |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
7 |
.. #. use the ``while`` loop |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
8 |
.. #. Use ``break``, ``continue`` and ``pass`` statements to play around |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
9 |
.. with loops. |
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
10 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
11 |
.. Prerequisites |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
12 |
.. ------------- |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
13 |
|
254
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
14 |
.. 1. getting started with ipython |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
15 |
.. #. getting started with for |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
16 |
.. #. conditionals |
c43677920502
added questions and pre-reqs to loops LO.
Puneeth Chaganti <punchagan@fossee.in>
parents:
253
diff
changeset
|
17 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
18 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
19 |
.. Author : |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
20 |
Internal Reviewer : |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
21 |
External Reviewer : |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
22 |
Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
23 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
24 |
Script |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
25 |
------ |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
26 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
27 |
{{{ Show the slide containing title }}} |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
28 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
29 |
Hello Friends. Welcome this tutorial on loops in Python. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
30 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
31 |
{{{ Show the outline slide }}} |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
32 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
33 |
In this tutorial, we shall look at ``while`` and ``for`` loops. We |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
34 |
shall then look at the ``break``, ``continue`` and ``pass`` keywords |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
35 |
and how to use them. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
36 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
37 |
{{{ switch to the ipython terminal }}} |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
38 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
39 |
We have an ``ipython`` terminal, that we shall use through out this |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
40 |
tutorial. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
41 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
42 |
We shall first begin with the ``while`` loop. The ``while`` loop is |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
43 |
used for repeated execution as long as a condition is ``True``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
44 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
45 |
Let us print the squares of all the odd numbers less than 10, using |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
46 |
the ``while`` loop. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
47 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
48 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
49 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
50 |
i = 1 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
51 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
52 |
while i<10: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
53 |
print i*i |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
54 |
i += 2 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
55 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
56 |
This loop prints the squares of the odd numbers below 10. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
57 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
58 |
The ``while`` loop, repeatedly checks if the condition is true and |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
59 |
executes the block of code within the loop, if it is. As with any |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
60 |
other block in Python, the code within the ``while`` block is indented |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
61 |
to the right by 4 spaces. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
62 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
63 |
Following is an exercise that you must do. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
64 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
65 |
%%1%% Write a ``while`` loop to print the squares of all the even |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
66 |
numbers below 10. Then, return to the video. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
67 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
68 |
Please, pause the video here. Do the exercise and then continue. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
69 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
70 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
71 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
72 |
i = 2 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
73 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
74 |
while i<10: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
75 |
print i*i |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
76 |
i += 2 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
77 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
78 |
Let us now solve the same problem of printing the squares of all odd |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
79 |
numbers less than 10, using the ``for`` loop. As we know, the ``for`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
80 |
loop iterates over a list or any other sequential data type. So, we |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
81 |
use the ``range`` function to get a list of odd numbers below 10, and |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
82 |
then iterate over it and print the required stuff. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
83 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
84 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
85 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
86 |
for n in range(1, 10, 2): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
87 |
print n*n |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
88 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
89 |
Following is an exercise that you must do. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
90 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
91 |
%%2%% Pause the video here and write a ``for`` loop to print the |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
92 |
squares of all the even numbers below 10. Then, return to the video. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
93 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
94 |
Please, pause the video here. Do the exercise and then continue. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
95 |
|
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
96 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
97 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
98 |
for n in range(2, 10, 2): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
99 |
print n*n |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
100 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
101 |
Let us now look at how to use the keywords, ``pass``, ``break`` and |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
102 |
``continue``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
103 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
104 |
As we already know, ``pass`` is just a syntactic filler. It is used |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
105 |
for the sake of completion of blocks, that do not have any code within |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
106 |
them. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
107 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
108 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
109 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
110 |
for n in range(2, 10, 2): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
111 |
pass |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
112 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
113 |
``break`` is used to break out of the innermost loop. The ``while`` |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
114 |
loop to print the squares of all the odd numbers below 10, can be |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
115 |
modified using the ``break`` statement, as follows |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
116 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
117 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
118 |
i = 1 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
119 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
120 |
while True: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
121 |
print i*i |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
122 |
i += 2 |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
123 |
if i<10: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
124 |
break |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
125 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
126 |
``continue`` is used to skip execution of the rest of the loop on this |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
127 |
iteration and continue to the end of this iteration. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
128 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
129 |
Say, we wish to print the squares of all the odd numbers below 10, |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
130 |
which are not multiples of 3, we would modify the for loop as follows. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
131 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
132 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
133 |
for n in range(1, 10, 2): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
134 |
if n%3 == 0: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
135 |
continue |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
136 |
print n*n |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
137 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
138 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
139 |
Following is an exercise that you must do. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
140 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
141 |
%%3%%Using the ``continue`` keyword modify the ``for`` loop to print |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
142 |
the squares of even numbers below 10, to print the squares of only |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
143 |
multiples of 4. (Do not modify the range function call.) |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
144 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
145 |
Please, pause the video here. Do the exercise and then continue. |
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
146 |
:: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
147 |
|
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
148 |
for n in range(2, 10, 2): |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
149 |
if n%4: |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
150 |
continue |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
151 |
print n*n |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
152 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
153 |
{{{ Show summary slide }}} |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
154 |
|
217
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
155 |
That brings us to the end of this tutorial. In this tutorial, we have |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
156 |
learnt about looping structures in Python and the use of the keywords |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
157 |
``pass``, ``break`` and ``continue``. |
b595f90016c5
Changed structure of my scripts.
Puneeth Chaganti <punchagan@fossee.in>
parents:
diff
changeset
|
158 |
|
253
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
159 |
{{{ Show the "sponsored by FOSSEE" slide }}} |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
160 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
161 |
This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
162 |
|
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
163 |
Hope you have enjoyed and found it useful. |
8a117c6e75f1
Fixed loops LO script.
Puneeth Chaganti <punchagan@fossee.in>
parents:
217
diff
changeset
|
164 |
Thank you! |