By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,850 Members | 1,005 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,850 IT Pros & Developers. It's quick & easy.

countint words from an input string

P: n/a
Hello!

Try to write som code that will get an input string from the user. Futher
more, I'd like to have the program to count all the word the user has
written.

Startet out like this:

/-------------
s = raw_input("Write a text line")
print s.split()
/----------------

How can I count the words in the split function. Do I have to use the split
function to count the words in the S variable?

Regards
Frengky

--
Organisation nr: 983063349
Frengky, Olsokveien 65,1727 Sarpsborg, Norway
Tel: +47 92611725
Fax: +47 69152017
Email: oy*************@frengky.no
Web: www.frengky.no
Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Fri, 7 Jan 2005 15:58:06 +0100, Řystein Western <in**@frengky.no> wrote:
Try to write som code that will get an input string from the user. Futher
more, I'd like to have the program to count all the word the user has
written.

Startet out like this:

/-------------
s = raw_input("Write a text line")
print s.split()
/----------------

How can I count the words in the split function.


print 'You've entered', len(s.split()), 'words.'

BTW, though newbie questions are quite welcome here, you might find it
beneficial to run through the Python tutorial (at
http://docs.python.org/tut/tut.html and included in the standard
distribution), and to join the tutor mailing list (at
http://mail.python.org/mailman/listinfo/tutor/).

--
Cheers,
Simon B,
si***@brunningonline.net,
http://www.brunningonline.net/simon/blog/
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.