import os def check_file_for_word(file_name, word): if not os.path.exists(file_name): return False with open(file_name, "r") as fp: contents = fp.read() return word in contents def are_anagrams(s, t): s = s.lower() t = t.lower() s = list(s) t = list(t) s.sort() # s = sorted(s) t.sort() # t = sorted(t) return s == t def sum_of_proper_divisors(n): total = 0 for k in range(1, n): if n%k == 0: total += k return total def is_perfect_number(n): #total is the sum of the proper divisors. return n == sum_of_proper_divisors(n) #is n the sum of its proper divisors? def contains_embedded_word(word, search_field): if word == "": return True if search_field == "": return False n = search_field.find(word[0]) if n == -1: return False search_field = search_field[n+1:] word = word[1:] return contains_embedded_word(word, search_field) print("Scott Laird, drumroll, PLEASE!!!") print(contains_embedded_word("dog", "donating")) print(not contains_embedded_word("god", "donating")) print(check_file_for_word("test.txt", "Pooh")) print(check_file_for_word("test.txt", "heffalump")) print(is_perfect_number(6)) print(is_perfect_number(12)) print(is_perfect_number(28)) print(is_perfect_number(496)) # 28 1 2 4 7 14