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")

      p =input("Enter a sentence: ")

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

Edited 6 Years Ago by Nick Evan: Added CODE-tags

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 3 Years Ago by mike_2000_17: Fixed formatting

I suppose when he type

words = line.split(p)

he meant

words = p.split()

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.