Sharing my word count code for the assignment in Session 3:
print("Word Count program executed. Enter the filename of a text file you wish to read:")
try:
file = open(input(''), 'r')
linecount = 0
wordcount = 0
charcount = 0
for line in file:
linecount = linecount + 1
charcount = charcount + len(line)
print("The specified file contains: ")
print("Lines: " + str(linecount))
print("Characters: " + str(charcount))
file.close()
file = open('test.txt', 'r')
data = file.read()
data = data.split(" ")
data = str(data).replace("\\n", " ")
data = data.split(" ")
wordcount = len(data)
print("Words: " + str(wordcount))
file.close()
except:
print("File does not exist")