&给你 2021-11-04 09:01 采纳率: 66.7%
浏览 106
已结题

用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.

  • 写回答

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))
    

    结果:

    img

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 11月4日
  • 已采纳回答 11月4日
  • 创建了问题 11月4日