# Demonstrates how to read and process information from text files def line_count(filename): """ Returns the number of lines in the provided file :param filename: (str) the name of the file to count its lines :return: (int) the number of lines in the provided file """ file = open(filename, "r") line_counter = 0 for line in file: line_counter += 1 file.close() return line_counter def print_file_almost(filename): """ Attempts to print the contents of the file :param filename: (str) the name of the file to print its lines :return: (None) """ myfile = open(filename, "r") for line in myfile: print(line) print(len(line)) myfile.close() def print_file(filename): """ Prints the contents of the file :param filename: (str) the name of the file to print its lines :return: (None) """ myfile = open(filename, "r") for line in myfile: line = line.strip() print(line) # print(line.strip()) myfile.close() def file_word_count(filename): """ Returns the number of words in the provided file :param filename: (str) the name of the file to count its words :return: (int) the number of words in the provided file """ f = open(filename, "r") word_count = 0 for line in f: line = line.strip() words = line.split() word_count += len(words) f.close() return word_count def capitalized_word_count(words): """ Returns the number of uppercase words in the provided list :param words: (list) the list to count its uppercase words :return: (int) the number of uppercase words in the provided list """ count = 0 for word in words: if word[0].isupper(): count += 1 return count def file_capitalized_count(filename): """ Returns the number of capitalized words in the provided file :param filename: (str) the name of the file to count its capitalized words :return: (int) the number of capitalized words in the provided file """ file = open(filename, "r") count = 0 for line in file: line = line.strip() words = line.split() num_cap = capitalized_word_count(words) count += num_cap file.close() return count