Python问题求解。

英语语法中动词的第三人称单数形式规则简要如下,如果动词以y字母结尾,则去掉y加上ies如果动词以o,ch,s,sh,x,z字母结尾,则加上es,默认直接在动词最后加上字母s。写一个程序,对于任意给定的一个动词返回其第三人称单数形式。

代码如下:

def myfun(s):
    n = len(s)
    if s.endswith('y'):
        s1 = s[0:n - 1]
        s1 = s1 + 'ies'
        print(s1)
    elif s.endswith('o') or s.endswith('ch') or s.endswith('s') or s.endswith('sh') or s.endswith('x') or s.endswith('z'):
        s1 = s + 'es'
        print(s1)
    else:
        s1 = s + 's'
        print(s1)

s = input()
myfun(s)



代码实现如下,望采纳

def get_third_person_form(verb):
  if verb.endswith('y'):
    return verb[:-1] + 'ies'
  elif verb.endswith(('o', 'ch', 's', 'sh', 'x', 'z')):
    return verb + 'es'
  else:
    return verb + 's'

print(get_third_person_form('try'))
print(get_third_person_form('watch'))
print(get_third_person_form('fix'))
print(get_third_person_form('run'))
print(get_third_person_form('wash'))
您好,我是有问必答小助手,您的问题已经有小伙伴帮您解答,感谢您对有问必答的支持与关注!
PS:问答VIP年卡 【限时加赠:IT技术图书免费领】,了解详情>>> https://vip.csdn.net/askvip?utm_source=1146287632