Do this activity with a partner. You don't have to turn anything in.
myString = 'hi there!'
len(myString)
myList = myString.split()
len(myList[1])
x = 10
y = 15
str(x) + str(y)
[x]+[y]
range(1,11)
range(3,10)[0] #this is tricky
negNums = range(-7,1)
negNums[3:5]
(x == 10) and (str(y) == 'fifteen')
(x < 4) or (y*0.1 < 4)
if len(myList[1]) > 10:
print myList[1],'has length > 10'
else:
print myList[1],'has length <= 10'
def tip(bill):
return bill * 0.15
tip(100.00)
Download and save ACT2-3.py. Open it in IDLE.
readMobyDick(). Make sure you understand the following line:
fileString = fileString[0:1000]
CountWordsInMobyDick(). Make sure you understand the following lines:
for word in myList:
count = count + 1
countWordsInMobyDick(). What's your answer?readMobyDick() to count all the words in MobyDick (hint: one of the lines is a print statement, which technically has no bearing on how the rest of the function executes). Press F5 again and run countWordsInMobyDick() again. What's your answer?avgWordLengthInMobyDick() function.
readMobyDick function you wrote.len function.float to make sure you're doing floating point (decimal) division, and return the average.getLongestWordInMobyDick() function.
readMobyDick function you wrote.