Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Python
counter=0
text=raw_input("text:")
for char in text:
    if char==" ":
         counter+=1
return counter



This code works for one line of code, but doesn't if text is more than one line (this happens of course because raw_input only collects one line of code(I think)). Is there any way I can get input from the user and--even if there is more than one line--return the number of words? Thanks!
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900