1 ======== |
1 .. Objectives |
2 Script |
2 .. ---------- |
3 ======== |
|
4 |
3 |
5 {{{ show the welcome slide }}} |
4 .. Clearly state the objectives of the LO (along with RBT level) |
6 |
5 |
7 Welcome this tutorial on loops in Python. |
6 .. Prerequisites |
|
7 .. ------------- |
8 |
8 |
9 {{{ show the outline slide }}} |
9 .. 1. Name of LO-1 |
|
10 .. 2. Name of LO-2 |
|
11 .. 3. Name of LO-3 |
|
12 |
|
13 .. Author : |
|
14 Internal Reviewer : |
|
15 External Reviewer : |
|
16 Checklist OK? : <put date stamp here, if OK> [2010-10-05] |
|
17 |
|
18 Script |
|
19 ------ |
|
20 |
|
21 {{{ Show the slide containing title }}} |
|
22 |
|
23 Hello Friends. Welcome this tutorial on loops in Python. |
|
24 |
|
25 {{{ Show the outline slide }}} |
10 |
26 |
11 In this tutorial, we shall look at ``while`` and ``for`` loops. We |
27 In this tutorial, we shall look at ``while`` and ``for`` loops. We |
12 shall then look at the ``break``, ``continue`` and ``pass`` keywords |
28 shall then look at the ``break``, ``continue`` and ``pass`` keywords |
13 and how to use them. |
29 and how to use them. |
14 |
30 |
36 The ``while`` loop, repeatedly checks if the condition is true and |
52 The ``while`` loop, repeatedly checks if the condition is true and |
37 executes the block of code within the loop, if it is. As with any |
53 executes the block of code within the loop, if it is. As with any |
38 other block in Python, the code within the ``while`` block is indented |
54 other block in Python, the code within the ``while`` block is indented |
39 to the right by 4 spaces. |
55 to the right by 4 spaces. |
40 |
56 |
41 E%% %% Pause the video here and write a ``while`` loop to print the |
57 Following is an exercise that you must do. |
42 squares of all the even numbers below 10. Then, return to the video. |
58 |
|
59 %%1%% Write a ``while`` loop to print the squares of all the even |
|
60 numbers below 10. Then, return to the video. |
|
61 |
|
62 Please, pause the video here. Do the exercise and then continue. |
43 |
63 |
44 :: |
64 :: |
45 |
65 |
46 i = 2 |
66 i = 2 |
47 |
67 |
58 :: |
78 :: |
59 |
79 |
60 for n in range(1, 10, 2): |
80 for n in range(1, 10, 2): |
61 print n*n |
81 print n*n |
62 |
82 |
63 E%% %% Pause the video here and write a ``for`` loop to print the |
83 Following is an exercise that you must do. |
|
84 |
|
85 %%2%% Pause the video here and write a ``for`` loop to print the |
64 squares of all the even numbers below 10. Then, return to the video. |
86 squares of all the even numbers below 10. Then, return to the video. |
|
87 |
|
88 Please, pause the video here. Do the exercise and then continue. |
65 |
89 |
66 :: |
90 :: |
67 |
91 |
68 for n in range(2, 10, 2): |
92 for n in range(2, 10, 2): |
69 print n*n |
93 print n*n |
104 if n%3 == 0: |
128 if n%3 == 0: |
105 continue |
129 continue |
106 print n*n |
130 print n*n |
107 |
131 |
108 |
132 |
109 E%% %%Pause the video here and using the ``continue`` keyword modify |
133 Following is an exercise that you must do. |
110 the ``for`` loop to print the squares of even numbers below 10, to |
134 |
111 print the squares of only multiples of 4. (Do not modify the range |
135 %%3%%Using the ``continue`` keyword modify the ``for`` loop to print |
112 function call.) Then, resume the video. |
136 the squares of even numbers below 10, to print the squares of only |
|
137 multiples of 4. (Do not modify the range function call.) |
|
138 |
|
139 Please, pause the video here. Do the exercise and then continue. |
113 :: |
140 :: |
114 |
141 |
115 for n in range(2, 10, 2): |
142 for n in range(2, 10, 2): |
116 if n%4: |
143 if n%4: |
117 continue |
144 continue |
118 print n*n |
145 print n*n |
119 |
146 |
|
147 {{{ Show summary slide }}} |
|
148 |
120 That brings us to the end of this tutorial. In this tutorial, we have |
149 That brings us to the end of this tutorial. In this tutorial, we have |
121 learnt about looping structures in Python and the use of the keywords |
150 learnt about looping structures in Python and the use of the keywords |
122 ``pass``, ``break`` and ``continue``. |
151 ``pass``, ``break`` and ``continue``. |
123 |
152 |
124 Thank You! |
153 {{{ Show the "sponsored by FOSSEE" slide }}} |
|
154 |
|
155 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India |
|
156 |
|
157 Hope you have enjoyed and found it useful. |
|
158 Thank you! |