countint words from an input string

  • Thread starter Øystein Western
  • Start date
Ø

Øystein Western

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: (e-mail address removed)
Web: www.frengky.no
 
S

Simon Brunning

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/).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,215
Messages
2,571,113
Members
47,710
Latest member
HarleyMoli

Latest Threads

Top