Longest shortest word

def smallest_largest_words(str1):
 word = ""
 all_words = []
 str1 = str1 + " "
 for i in range(0, len(str1)):
  if str1[i] != ' ':
   word = word + str1[i]
 else:
  all_words.append(word)
  word = ""
  small = large = all_words[0]

# Find smallest and largest word in the str1

 for k in range(0, len(all_words)):
  if len(small) > len(all_words[k]):
  small = all_words[k]
 if len(large) < len(all_words[k]):
  large = all_words[k]
  return small, large

myfile = open("test.txt", "w")
line = input("Enter text: ")
myfile.write(line)
myfile.close()

myfile = open("test.txt", "r")
lines = myfile.read()

small, large = smallest_largest_words(lines)
print("Smallest word: " + small)
print("Length of the shortest word=", len(small))
print("Largest word: " + large)
print("Length of the longest word=", len(large))