Basically she has a text file that has a list of words and needs to count how many words are in the file. It would actually appear to me that she only needs to count the number of lines since there are no lines with multiple words (ie. each line is one word, in a list format). So we don't need to worry about getting rid of whitespace or anything. We want to output a text file with the number of words written in it as well.
So:
filename = 'C:\Users\Chris\Desktop\test.txt' int words = 0 textfile = open(filename, 'r') for wordcount in textfile Something here words++
I'm not familiar with what to use in python. In java I would use a while loop as long as input.hasNextLine() and increment the counter every time I input.nextLine();
What would the equivalent be here?

New Topic/Question
Reply



MultiQuote






|