Write a program that requests the user to enter a sentence and checks whether the sen- tence contains extra (i.e., double) spaces between words. If so, the program should remove the extra space. For example, "Hello World" should be "Hello World". (Hint: Use split and join.)
What will be an ideal response?
```
# Check double spacing in a sentence.
import string
print "This program checks for double spacing in a sentence"
sentence = raw_input( "Enter a sentence: " )
newsentence = []
extraSpace = 0
# split sentence into words
sentence = string.split( sentence, " " )
# check double spacing
for word in sentence:
# non-space word
if word != "":
newsentence.append( word )
else:
print "removing extra space ..."
extraSpace += 1
# output the result
if extraSpace == 0:
print "The input sentence does not contain double spacing"
else:
correctSentence = " ".join( newsentence )
print "New sentence: %s" % correctSentence
```
This program checks for double spacing in a sentence
Enter a sentence: I am a student.
removing extra space ...
removing extra space ...
New sentence: I am a student.
You might also like to view...
A host has been assigned the address 169.254.0.1. This is an example of which of the following address types?
A. APIPA B. MAC C. Static D. Public
EPS files can contain both bitmap and vector graphics.
Answer the following statement true (T) or false (F)