473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Breaking down sentances

16
thanks for your help with my previous problem but i got another one hopefully this doesnt bother you guys at all. how do i go about writing a program that counts the number of words in a sentence by the user and make sure that it calculates the avrage word length of that sentence. thanks once again
May 13 '07 #1
7 1985
bartonc
6,596 Expert 4TB
thanks for your help with my previous problem but i got another one hopefully this doesnt bother you guys at all. how do i go about writing a program that counts the number of words in a sentence by the user and make sure that it calculates the avrage word length of that sentence. thanks once again
It's really no trouble. Software development help is what TheScripts.com is all about.

It really helps us help you if you post some code that shows what you able to do and what you are having trouble with. Also, good thread titles help people know what your problem is in general. There are some Posting Guidelines here. Please take some time to read through some of them.

Thanks for seeking help on the Python Forum,
Barton
May 13 '07 #2
ghostdog74
511 Expert 256MB
thanks for your help with my previous problem but i got another one hopefully this doesnt bother you guys at all. how do i go about writing a program that counts the number of words in a sentence by the user and make sure that it calculates the avrage word length of that sentence. thanks once again
assuming words are separated by spaces(one or more)
here's a rough pseudocode:
Expand|Select|Wrap|Line Numbers
  1. prompt user for sentence # raw_input()
  2. split the sentence by spaces and store somewhere # split() and list storage
  3. count the length of the list # len()
  4.  
however i don't understand what you meant by avg word length, so i leave it to you for clarification.
May 14 '07 #3
Kasrav
16
assuming words are separated by spaces(one or more)
here's a rough pseudocode:
Expand|Select|Wrap|Line Numbers
  1. prompt user for sentence # raw_input()
  2. split the sentence by spaces and store somewhere # split() and list storage
  3. count the length of the list # len()
  4.  
however i don't understand what you meant by avg word length, so i leave it to you for clarification.
avg is the average word lenght in the sentnce so the average of the words in that sentence
May 20 '07 #4
bartonc
6,596 Expert 4TB
Expand|Select|Wrap|Line Numbers
  1. s = "This is a very short sentance. And this is one that\nspans lines."
  2. print s
  3. ##This is a very short sentance. And this is one that
  4. ##spans lines.
  5.  
  6. sentances = s.split(".")
  7. print sentances
  8. ['This is a very short sentance', ' And this is one that\nspans lines', '']
  9.  
  10. nWords = 0
  11. nCharacters = 0
  12.  
  13. for sentance in sentances:
  14.     if sentance:
  15.         words = sentance.split()
  16.         for word in words:
  17.             nWords += 1
  18.             nCharacters += len(word)
  19.  
  20. avgWordLen = nCharacters/float(nWords)
  21.  
  22. print "Number of words = %d, with a total of %d charaters.\nSo the average word length is %.4f"\
  23. %(nWords, nCharacters, avgWordLen)
  24.  
This is a very short sentance. And this is one that
spans lines.
['This is a very short sentance', ' And this is one that\nspans lines', '']
Number of words = 13, with a total of 50 charaters.
So the average word length is 3.8462
May 20 '07 #5
Kasrav
16
thanks for the help you guys its really good i want to also find out what is the best book for python would you reccommend for a someone who is quite new to python.
May 29 '07 #6
bartonc
6,596 Expert 4TB
thanks for the help you guys its really good i want to also find out what is the best book for python would you reccommend for a someone who is quite new to python.
As stated in this thread (found by searching TheScripts for python books),

Learning Python
by Mark Lutz and David Ascher
publisher: O'Reilly
May 29 '07 #7
ghostdog74
511 Expert 256MB
thanks for the help you guys its really good i want to also find out what is the best book for python would you reccommend for a someone who is quite new to python.
i always recommend the Python doc site. It has many resources you can look at, esp take the tutorial by the Python creator himself. Also once you get the hang, look through the library references etc..
May 29 '07 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: MarionEll | last post by:
--------------------------------------------------------- ************* Call for Participation ************** ************ Late Breaking News ************* *********** Extreme...
0
by: Amy | last post by:
I am looking for an rss feed that contains really important breaking news like "A large Tsunami just hit Asia" or "Terrorists attack the World Trade Center", but is empty if there really isn't...
2
by: Jacob | last post by:
A problem I've been rather stuck on and, try as I might, have not been able to find the answer to. I've written a nice little class that I want to include in another project. The class works...
27
by: The Bicycling Guitarist | last post by:
Hi. I found the following when trying to learn if there is such a thing as a non-breaking hyphen. Apparently Unicode has a ‑ but that is not well-supported, especially in older browsers. Somebody...
22
by: stevenkobes | last post by:
If a word has a hyphen in it, IE will permit a line break at the hyphen, but Firefox/Mozilla won't. Apparently the Firefox behavior is standards-compliant, but it is not what I want. Is there a...
4
by: John Wood | last post by:
I saw that Microsoft have released a list of breaking changes in .Net here: http://msdn.microsoft.com/netframework/programming/breakingchanges/runtime/default.aspx While this is useful, it seems...
150
by: tony | last post by:
If you have any PHP scripts which will not work in the current releases due to breaks in backwards compatibility then take a look at http://www.tonymarston.net/php-mysql/bc-is-everything.html and...
3
by: Beowulf | last post by:
I have data coming from a telephony system that keeps track of when an employee makes a phone call to conduct a survey and which project number is being billed for the time the employee spends on...
28
by: Useful Info | last post by:
Like on 9/11, the Federal Government apparently WANTED people to die at the hands of Cho at VA Tech, because they told campus police not to pursue Cho after the double homicide occurred. Story...
7
by: dorandoran | last post by:
I am updating local sql server based on web services data. When I do a query how many updates I have to make it comes to be more than 4000 records. Now the problem is time-out issue and so many other...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.