float
).[2,5,9]
to a variable called myList
. Write an expression that averages the elements of myList
."2 5 9"
to a variable called myString
. Using indexing, write an expression that just returns "2"
. Do the same for "5"
and "9"
.Consider the following Python program. The numbers to the left of the green line are just line references, and not part of the program; you wouldn't type them if you were writing this program yourself.
y = 10 x = y + 5 def addOne(t): y = t + 1 return y z = addOne(x) z y
Starting at Line 1, go through the program and write down the variable table (like we just did in class). What does z
output in Line 9? What does y
output in Line 10?
split
function, without an input argument, splits a string on any whitespace (including spaces, newlines, tabs, etc.). Use the expression fileString.split(<delimiter>)
to split on different delimiters by passing a string delimiter as input to the split
function. Observe what happens when the delimiter is:
"\n"
"a"
"Sarah"
ACT2-1.py
, write a function called readShel
that opens the poem and returns a list of words. We have already written each line in class already — you just need to put them together.Download and save MobyDick.txt
. In ACT2-1.py
, write a readMobyDick()
function and a countWordsInMobyDick()
function. Note that only a few things change from the Shel
functions.
Be sure to save this python file! It will be useful for the next class.