Lecture 11: Iteration and For‐Loops
(Sections 4.2 and 10.3) CS 1110 Introduction to Computing Using Python
[E. Andersen, A. Bracy, D. Fan, D. Gries, L. Lee,
- S. Marschner, C. Van Loan, W. White]
http://www.cs.cornell.edu/courses/cs1110/2020sp
Lecture 11: Iteration and For Loops (Sections 4.2 and 10.3) CS 1110 - - PowerPoint PPT Presentation
http://www.cs.cornell.edu/courses/cs1110/2020sp Lecture 11: Iteration and For Loops (Sections 4.2 and 10.3) CS 1110 Introduction to Computing Using Python [E. Andersen, A. Bracy, D. Fan, D. Gries, L. Lee, S. Marschner, C. Van Loan, W. White]
[E. Andersen, A. Bracy, D. Fan, D. Gries, L. Lee,
http://www.cs.cornell.edu/courses/cs1110/2020sp
Revision window closes Tu Mar 3.
cs1110‐prof, cs1110‐staff)
will allow late requests on CMS until 11:59pm Feb 27, but no promise
you have not received email from us about arrangements for prelim 1.
academic integrity!
2
No-laptop zone on your left
front
3
4
5
6
To execute the for-loop:
grades has more elements put next element in x
True False
print(x)
7
8
9
same code same code
10
11
same code same code
12
same code same code
13
14
same code same code
15
16
17
18
19
20
21
22
24
25
26
27
1 2 id4 5 4 7 grades id4 add_one the_list 1 id4 1 2
28
1 2 1 2 id4 5 4 7 grades id4
add_one the_list 1 2 id4
x 5
29
1 2
add_one the_list 1 2 1 id4 x 1 2 id4 5 4 7 grades id4
Loop back to line 1
5 6
30
1 2
add_one the_list 1 2 1 2 id4
x 1 2 id4 5 4 7 grades id4
5 6 4
31
1 2 add_one the_list 1 2 1 2 1 id4
x 1 2 id4 5 4 7 grades id4
Loop back to line 1 5 6 4 5
32
1 2
add_one the_list 1 2 1 2 1 id4
x 1 2 id4 5 4 7 grades id4
2
5 6 4 5 7
33
1 2 add_one the_list 1 2 1 2 1 id4
x 1 2 id4 5 4 7 grades id4
Loop back to line 1
2 1
5 6 4 5 7 8
34
1 2
add_one the_list id4
x RETURN NONE 1 2 id4 5 4 7 grades id4
1 2 1 2 1
2 1
5 6 4 5 7 8
add_one the_list id4
x RETURN NONE
35
1 2 1 2 id4 5 4 7 grades id4
1 2 1 2 1
2 1
5 6 4 5 7 8
36
37
38