Here's the logic. You have to add the code to take input from text file:
ch_count = 0
word_count = 1
chars = []
words = []
chars1 = []
words1 = []
rep_char = 0
rep_word = 0
word_i = 0
if test:
for i in range(0,len(test)):
if test[i] is not " ":
ch_count+=1
if test[i] in chars:
if test[i] not in chars1:
chars1.append(test[i])
rep_char+=1
else:
chars.append(test[i])
else:
word_count+=1
print(test[word_i:i])
if test[word_i:i] in words:
if test[word_i:i] not in words1:
words1.append(test[word_i:i])
rep_word+=1
else:
words.append(test[word_i:i])
print(words, words1)
try:
word_i = i+1
except:
pass
print(test[word_i:])
if test[word_i:] in words:
if test[word_i:] not in words1:
rep_word+=1
if test[-1] is " ":
word_count-=1
print('Total number of characters: '+str(ch_count))
print('Total number of words: '+str(word_count))
print('Repeated characters: '+str(rep_char))
print('Repeated Words: '+str(rep_word))