I'm trying to calculate the average length of sentences in a .txt file by dividing the number of words by number of full stops:-
def divide(x, y):
return x / y
file = open("File One.txt", "r")
data = file.read()
words = data.split()
print('Number of words in text file:', len(words))
count = data.count('.')
print("Number of full stops:", count)
num1 = words
num2 = count
print("Average sentence length:", divide(num1, num2))
But I end up with:-
Number of words in text file: 25
Number of full stops: 3
Traceback (most recent call last):
File "C:\Users\Jonathan\Desktop\Data\stripped down.py", line 16, in <module>
print("Average sentence length:", divide(num1, num2))
File "C:\Users\Jonathan\Desktop\Data\stripped down.py", line 2, in divide
return x / y
TypeError: unsupported operand type(s) for /: 'list' and 'int'
Any help or advice would be appreciated.