I'm having a tough time figuring this out.

we need to fill in the blanks

import ____________

def wordCount():

    lineCnt = 0
    wordCnt = 0
    charCnt = 0
    list = []
    
    ______________ = _______________("Enter the filename : ")

    file = ________(filename, __________)

    for _________ in file:

        ____________ += 1

        list = string.____________(line, ' ')

        wordCnt = wordCnt + len(_________)

        for ch in _________:

            ____________ += 1

    print ___________, "lines"

    print ___________, "words"

    print ___________, "characters"

    file.____________()

wordCount()

this is what I have gotten so far.

import string

def wordCount():

    lineCnt = 0
    wordCnt = 0
    charCnt = 0
    list = []
    
    file = raw_input("Enter the filename : ")

    file = ________(filename, file)

    for range in file:

        lineCnt += 1

        list = string.____________(line, ' ')

        wordCnt = wordCnt + len(_________)

        for ch in file:

            charCnt += 1

    print lineCnt, "lines"

    print wordCnt, "words"

    print charCnt, "characters"

    file.____________()

wordCount()

Thanks in advance

Member Avatar for masterofpuppets

i'll try to explain what's going on here :)

import string
 
def wordCount():
 
    lineCnt = 0
    wordCnt = 0
    charCnt = 0
    list = []
 
    file = raw_input("Enter the filename : ")
 
    file = open( filename, file ) # you need to open the file in order to process the info in it
 
    for range in file:
 
        lineCnt += 1
 
        list = string.split( line, ' ' ) #Split the line
 
        wordCnt = wordCnt + len( list ) # the length of the list containing the split line, i.e. number of words in current line
 
        for ch in file:
 
            charCnt += 1
 
    print lineCnt, "lines"
 
    print wordCnt, "words"
 
    print charCnt, "characters"
 
    file.close() #close the file after the processing is done
 
wordCount()

hope this helps :)

i'll try to explain what's going on here :)

import string
 
def wordCount():
 
    lineCnt = 0
    wordCnt = 0
    charCnt = 0
    list = []
 
    file = raw_input("Enter the filename : ")
 
    file = open( filename, file ) # you need to open the file in order to process the info in it
 
    for range in file:
 
        lineCnt += 1
 
        list = string.split( line, ' ' ) #Split the line
 
        wordCnt = wordCnt + len( list ) # the length of the list containing the split line, i.e. number of words in current line
 
        for ch in file:
 
            charCnt += 1
 
    print lineCnt, "lines"
 
    print wordCnt, "words"
 
    print charCnt, "characters"
 
    file.close() #close the file after the processing is done
 
wordCount()

hope this helps :)

thank you it does.

These two lines:
______________ = _______________("Enter the filename : ")
file = ________(filename, __________)

should be:
filename = raw_input("Enter the filename : ")
file = open(filename, "r")

Picking file as a variable name is a little unfortunate, since file is a function name in Python2.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.