using the python
Write a function oneSpaceAfterPeriod( String Parameter ) that
will return a string with one space after every period. Another
function twoSpaceAfterPeriod (String Parameter) that will return a
string with two spaces after every period.
It is also a common error to forget to capitalize the first word
after a period. Write a function to correct this and return the
corrected paragraph.
Here are both the functions with a test example. Thank you.
def oneSpaceAfterPeriod(str1):
str2 = ""
length = len(str1)-1
flag = True
i=0
j = length
while(flag):
if(length==0):
flag =
False
if(str1[i]=="." and i!=j):
str2+=str1[i]
str2+=" "
str2+=str1[i+1].capitalize()
i+=1
length=length-1
else:
str2+=str1[i]
i+=1
length=length-1
return str2
def twoSpaceAfterPeriod(str1):
str2 = ""
length = len(str1)-1
flag = True
i = 0
j = length
while(flag):
if(length == 0):
flag = False
if(str1[i]=="." and i!=j):
str2+=
str1[i]
str2+=" "
str2+=" "
str2+=str1[i+1].capitalize()
i+=1
length =
length-1
else:
str2+=
str1[i]
i+=1
length= length-1
return str2
text = "There are spaces.there is no space.is there."
val = oneSpaceAfterPeriod(text)
print(val)
val2 = twoSpaceAfterPeriod(text)
print(val2)
So those are the function which could used with text to give the periods and the gap with capatalization.
Thank you.
Get Answers For Free
Most questions answered within 1 hours.