Нема описа

alice.py 418B

1234567891011121314
  1. filename = 'alice.txt'
  2. try:
  3. with open(filename, encoding='utf-8') as f_obj:
  4. contents = f_obj.read()
  5. except FileNotFoundError as e:
  6. msg = "Sorry, the file " + filename + " does not exist."
  7. print(msg)
  8. else:
  9. # Count the approximate number of words in the file.
  10. words = contents.split()
  11. num_words = len(words)
  12. print("The file " + filename + " has about " + str(num_words) + " words.")