Scientific Computing
Create a file activity17.py
in your cs100/ch4
folder.
myString = 'abc'
myString[0] = 'd'
print(myString)
myList = ['a', 'b', 'c']
myList[0] = 'd'
print(myList)
k1
, k2
, and k3
?
s = "I like apples"
k1 = s.split()
k2 = s.split('a')
k3 = s.split('e')
"mississippi"
into a list uing the 'i'
as a split point. Print the result.numWords(sentence)
which takes a string as a parameter and returns the number of words in the given string. Call your function to print the number of words in the sentence "the quick brown fox"
Hint: use split.checkIn(myList, key)
that works similar to (but does not use) in
. It returns True
if the given key is in list, and False
otherwise.indexOf(myList, key)
that works similar to (but does not use) index
. It should return the index where key belongs in myList, or -1 if it is not in the list.shuffle
that takes a list as a prameter and returns a new list with the elements shuffled in a random order. Print out the original and the returned list to ensure the original list is in tact and the returned list is shuffled.Submit your working activity17.py
to Moodle.