(๑•॒̀ ູ॒•́๑)嘟嘟嘟 2022-03-19 21:02 采纳率: 73.7%
浏览 63
已结题

Python单词尾缀的分析判断和提取

Python如何编写下列程序
给定单词为needed、raining、jumping、jumped、started,stars,请用if条件语句判断下列单词是ed结尾单词,或ing结尾单词,或其他类型。最终把三种类型的单词,分开打印(如下格式)。
ed结尾单词:
needed
jumped
started
ing结尾的单词;
rainig
jumping
其他类型的单词:
stars

  • 写回答

2条回答 默认 最新

  • CSDN专家-showbo 2022-03-19 21:13
    关注

    题主要的代码如下

    img

    lst1='needed、raining、jumping、jumped、started、stars'.split('、')
    lsted=[]
    lsting=[]
    lstother=[]
    for word in lst1:
        if word.endswith('ed'):
            lsted.append(word)
        elif word.endswith('ing'):
            lsting.append(word)
        else:
            lstother.append(word)
    print('ed结尾单词:')
    print('\n'.join(lsted))
    print('ing结尾单词:')
    print('\n'.join(lsting))
    print('其他类型的单词:')
    print('\n'.join(lstother))
    
    

    img

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

报告相同问题?

问题事件

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