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.

Computer Science & Information Technology

You might also like to view...

The action attribute is a required attribute of the ____ element.

A. bdo B. form C. area D. textarea

Computer Science & Information Technology

High-speed connections to the Internet are known as ________

A) analog B) broadband C) multicast D) baseband

Computer Science & Information Technology

Which of the following is NOT a technology typically used by spyware?

A. Automatically download software B. Disk drive formatting software C. Tracking software D. System modifying software

Computer Science & Information Technology

You can change the outline shape of an image either with or without a border

Indicate whether the statement is true or false

Computer Science & Information Technology