Oct 26, 2019 in Python 1,116 views

## 1 answer to this question.

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))
```
answered Oct 28, 2019 by
• 69,190 points

+1 vote

## I am trying to write a program in python for the occurrences of a character given the start and stop values of that string only using while

Here's the code: check = input("Enter the character: ...READ MORE

## Write a Python program that takes as input a month and year, determines how many days are in the month, and outputs the number of days. Thirty days are in September, April, June, and November

Write a Python program that takes as ...READ MORE

## I have a file of type text and fields separated with 'tab' so how to get avroschema from input text file in python

i have textfile now i want to ...READ MORE

## How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

–1 vote

## How to filter out any digit that contains odd number in a range of number in Python?

n = list(range(10)) b = list(filter(lambda i:i%2!=0,n)) print(b) READ MORE

## How can I write a program to add two numbers using functions in python?

there is sum() function as a built ...READ MORE

+1 vote

## Sum the values of column matching and not matching from a .txt file and write output to a two different files using Python

Name                                                    value DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 15657 DR_CNDAOFSZAPZP_GPFS_VOL.0 139264 DR_CNDAOFSZAPZP_GPFS_VOL.1 156579 DR_CNDAOFSZAPZP_GPFS_VOL.2 156579 DR_CNDAOFSZAPZP_GPFS_VOL.3 ...READ MORE

## What is the syntax of USE statement in MySQL?

The USE statement is used to mention ...READ MORE

–1 vote