Practice Lab Practical
###################Problem 1##############################
def countWords(s):
"""
countWords("I eat cake") -> 3
countWords("") -> 0
countWords("To be or not to be, that is the question.") -> 10"""
pass
def checkFileForWord(fileName, word):
"""
fileName is a string
if the file does not exist, return False
if the file does exist, check for word being a
substring of the file; if you find it return True and
return False otherwise"""
pass
###################Problem 3##############################
def weaveStrings(s,t):
""" weaveStrings("cat", "dog") -> "cdaotg"
weaveStrings("nasty", "cow") -> "ncaowty"
weaveStrings("cosmic", "eat") -> "ceoamtic" """
pass
###################Problem 4##############################
def areAnagrams(s,t):
""" s and t are strings
return True if s and t are anagrams, case INSENSITIVE
areAnagrams('space', 'Capes') -> True
areAnagrams('spatter', 'parsers') -> False
areAngrams('dog', 'log') -> False"""
pass
###################Problem 5##############################
def isPerfectNumber(n):
"""
n is a positive integer and n >= 2
n is perfect if it is the sum of its proper divisors.
6 has proper divisors 1,2,3 so isPerfectNumber(6) -> True
12 has proper divisors 1,2,3,4,6, which sum to 22,
so isPerfectNumber(12) -> False
Hint: You might want to write a helper function
sumOfProperDivisors(n)
"""
pass
###################Problem 6##############################
def containsEmbeddedWord(word, searchField):
"""
word is a string of letters
searchField is a string
returns True if the letters in word can be found in
order in the string searchField. This is case-insensitive
containsEmbeddedWord("abcd, "abcessed") -> True
containsEmbeddedWord("foot, "flounder of trust") -> True
containsEmbeddedWord("dequeue", "defend the queen") -> False"""
pass