Computes the average word length for all the words in a file?
average, file, python
Solution
wi = length of word i
wavg = ∑ wi / N
with open(input('Enter file name: '),'r') as f:
w = [len(word) for line in f for word in line.rstrip().split(" ")]
w_avg = sum(w)/len(w)
Problem
So i need to write a program that computes the average word length for all the words in a file. So far i have this and am totally lost ``` newfile=input('Enter file name: ') f=open(newfile,'r') count1=0 count2=0 for line in f: count1+=1 words=line.rstrip().split() for word in words: count2+=1 average=count1/count2 print('Average words per line: ',average) ```