用python纠正英文中的错误,该怎么做呀?求朋友们告知

用python纠正英文中的错误,该怎么做呀?求朋友们告知

问题描述:

3、编写一段程序,实现纠正一段英文中的两种错误:(1)单独字母“I”误写为“i”的情况;(2)以及单词中间字母“i”误写为“I”的情况。运行结果如图3所示。
测试用短文:
i am a student. I am sIx years old. i like read book. I lIke play the piano.
I am a unIversity student. i major in Information management and informatIon system.


a = """i am a student. I am sIx years old. i like read book. I lIke play the piano.
I am a unIversity student. i major in Information management and informatIon system.
"""
b = list(a)
error1 = 0 # I误写为i的次数
error2 = 0 # i误写为I的次数
for index,c in enumerate(b):
    if c == "i" and b[index + 1] == " ":# 如果是小写的字符,并且它的下一个是空格
        b[index] = "I"
        error1 += 1
    elif c == "I" and b[index+1] != " ":
        b[index] = "i"
        error2 += 1
b = "".join(b)
print("原句子: ")
print(a)
print("修改后: ")
print(b)

print("I误写为i的情况有{}处; i误写为I的情况有{}处.".format(error1,error2))

结果:

img

如果觉得答案对你有帮助,请点击下采纳,谢谢~

a='i am a student. I am sIx years old. i like read book. I lIke play the piano. \
I am a unIversity student. i major in Information management and informatIon system.'
b=a.replace('I','i').replace('i ','I ')
print(b)