use import whitespace instead. import sys
from collections import Counter
import string

def read_file(filename):
    with open(filename, 'r') as f:
        contents = f.read()
    return contents

def find_most_common_letter(contents):
    non_whitespace_chars = [c for c in contents if c not in string.whitespace]
    letter_counts = Counter(non_whitespace_chars)
    most_common_letter, count = letter_counts.most_common(1)[0]
    return most_common_letter, count

def find_percentage_of_word(contents, word):
# Convert to lowercase
    contents = contents.lower()
# Lowercase word and both cases of "the" and "The"
    word_count = Counter([w.lower() for w in contents.split() if w.strip(string.punctuation) == word.lower()]).get(word.lower(), 0)
# Total number of lowercase words
    total_words = len([w.strip(string.punctuation) for w in contents.split()])
    percent = (word_count / total_words) * 100
    return word_count, total_words, percent

def write_first_10_words_to_file(contents):
    words = contents.split(None, 10)[:10]
    with open('Exercise_8_output.txt', 'w') as f:
        f.write(' '.join(words))

if __name__ == "__main__":
    filename = sys.argv[1]
    contents = read_file(filename)
    most_common_letter, count = find_most_common_letter(contents)
    print(f"{most_common_letter} is the most common letter. It occurs {count} times.")
    word_count, total_words, percent = find_percentage_of_word(contents, 'the')
    print(f"'The' is {word_count} of {total_words} words or {percent:.2f}%.")
    write_first_10_words_to_file(contents)

