0

Hi, guys I'm having trouble writing this word count program in python3. I've been able to find alot of help for past versions but nothing for 3.

It is just a simple word count program, with a user input sentence.

So far I have

def main():
 
      print ("This program calculates the number of words in a sentence")
   

      print
   
      p =input("Enter a sentence: ")

      words = line.split(p)
   
      wordCount = len(words)
   
      print ("The total word count is:", wordCount)
   
main()

Edited by Nick Evan: Added CODE-tags

3
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by griswolf
1

Two things:

  1. You should use the (CODE) button around your code: It saves indentation, does keyword coloring, adds line numbers. All good things
  2. What is this line doing? words = line.split(p).

I don't see any declaration of the variable line... and suspect you have cut and pasted something without completely finishing the fixup needed.

Edited by mike_2000_17: Fixed formatting

1

I suppose when he type

words = line.split(p)

he meant

words = p.split()
0

I suppose that if he doesn't respond after some days then he is not interested any more. (probably he solved his own problem and does not care to spend time at DaniWeb)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.