Write a program that reads in a sentence of up to 100 characters and outputs the
ID: 3771074 • Letter: W
Question
Write a program that reads in a sentence of up to 100 characters and outputs the sentence with spacing corrected and with letters corrected for capitilization. In other words, in the output sentence , all strings of two or mor blanks should be compressed to a single blank. The sentence should start with an uppercase letter but should contain no other uppercase letters. Do not worry about propr names; if their first letters are changed to lowercase, that is acceptable. Treat a line break as if it were a blank, in the sense that a line break and any number of blanks are compressed to a single blank. Assume that the sentence neds with a period and contains no other periods. For example, the input
the Answer to life, the Universe, and everything IS 42.
sould produce the following output:
The answer to life, the universe, and everything is 42.
Explanation / Answer
import re
def sentenceFix(line):
line = re.sub(r's{2,}', " ", line)
line = line.lower()
line = line[0].upper() + line[1:]
return line
print sentenceFix("the Answer to life, the Universe, and everything IS 42")
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.