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.
用python纠正英文中的错误,该怎么做呀?求朋友们告知
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
2条回答 默认 最新
Fioman_Hammer 2021-11-04 14:41关注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))结果:

如果觉得答案对你有帮助,请点击下采纳,谢谢~本回答被题主选为最佳回答 , 对您是否有帮助呢?评论 打赏 举报解决 1无用