def main():

  p =input("Enter your sentence: ")

  words = p.split()

  wordCount = len(words)

  print ("The word count is:", wordCount)

main()

I get the read out:
Enter your sentence: Hello world
Traceback (most recent call last): File "C:/Python27/idk.py", line 11, in <module> main() File "C:/Python27/idk.py", line 3, in main p =input("Enter your sentence: ") File "<string>", line 1 Hello world ^ SyntaxError: unexpected EOF while parsing
What am i doing wrong? D:

Edit:

Figured it out. Input -> raw_input

Edited 3 Years Ago by Cassidy_2

Whoops, sorry, title should read: Need help writing a Python script that will input a sentence and count the number of words it contains.

Problem is:

You're typing in Python 3 code and using Python 2 to run it.

Python 3 is not backwards compatible with Python 2, so that means that you won't be able to run the code with the Python 2 interpreter.

It would be better for you to learn Python 3 simply because it's the latest supported version and because it's better to adapt to seeing as it's being adopted as standard.

Since you're obviously on Windows, the obvious solution is to install Python 3 and then follow the next steps for Windows 7, and 8 listed below:

[Win7 & Earlier]

Click START

  1. Type "run" (without quotes)
  2. In the box that pops up, type "cmd" (without quotes)
  3. Then in cmd, type:

set path=%path%;C:\Python33\

And then you're done.

[Win8]

Go to metro and start typing "cmd".
Then in cmd type:

set path=%path%;C:\Python33\

The results should be the same.

Actually Python2 has an input() function, but it is supposed to be for numeric input only. Python3 has changed that to string input and done away with raw_input().

This question has already been answered. Start a new discussion instead.