I need to prompt a user to type in a text file name and then take that file and and count the amount of words in the file. I have this code which counts the words in a file(that may not be "perfectly" written). I cannot figure out how to take the prompt text file and and get those words counted. I add a first line of say text = raw_input("enter a text file name: ") but I cannot take the file name given and have the words counted.
text = open("rainfall.txt", "r") for t in text: words = t.split() wordCount = len(words) print wordCount text.close()