



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




1
2
Assignment 2 will be posted tomorrow (Tuesday)
For programming in Python, make also use of online sources (e.g, tutorial at http://docs.python.org/tut/tut.html, see also http://www.python.org/doc/).
Information about 1st midterm (Monday, April 21) will be posted starting Wednesday this week Sample midterm Solutions to sample midterm Sections of the textbook to study 1st midterm has a multiple-choice and a program part
3
In the previous lecture...
Strings are indexed 0 – length of the string -1 ( len (x))
Individual characters and substrings can be accessed and assigned to variables:
4
Loop Structures
Linear sequence of instructions (Python statements) typically input, sequence of computations, output
depending on the user input depending on some computation ....
Sections 2.6 & 8.
7
Most simple example
for i in range(10):
print i
Note that here i starts with 0 !!
This is always the case if you don’t specify a start explicitly.
8
A more complex example
9
...and one more Compute the sum of N integers; N is input by the user
10
Comments on the previous loop
When programming, it is sometimes useful to add some "debug" info: adding print statements can help to find problems! Concepts to understand: variable initialization ( sum = 0 ) iteration variable (the one bound via for
13
More for-loop examples
14
"Unrolling" a for loop
y = 1 * 1 print "X =", 1 , print "y =", y
y = 2 * 2 print "X =", 2 , print "y =", y
y = 3 * 3 print "X =", 3 , print "y =", y
y = X * X print "X =", X, print "y =", y
X = 1
X = 2
X = 3