Discuss the homework due today, on strings, lists, and files.
I've posted my sample solutions and will go over them.
Upcoming schedule: no class Thursday ... so think next chapter homework, on functions, will be due Thursday next week rather than Tuesday.
This is some of the most important material of the term.
And I want to add a bit more stuff : doc strings & doc tests.
Topics to discuss :
We'll look at lots of examples in class ... and with the online "visualize python" tool.
# An optional argument with a default value.
def scale(x, multiplier=2):
""" Return x * multiplier """ # <= doc string
return multiplier * x
print("twice 10 is {}".format( scale(10) ))
print("triple 10 is {}".format( scale(10, 3) ))
# Is x modified ?
def double(y):
y = 2*y
return y
x = 10
double_x = double(x)
print("x is ", x)
print("double_x is ", double_x)
# Is numbers modified ?
def double_all(them):
for i in range(len(them)):
them[i] = 2 * them[i]
return them
numbers = [10, 11, 12]
double_numbers = double_all(numbers)
print("numbers is ", numbers)
print("double_numbers is ", double_numbers)
Hmmm. Run these in pythontutor.com to see exactly what's going on ...