Discuss / Python / 作业打卡

作业打卡

Topic source

凡九朵

#1 Created at ... [Delete] [Delete and Lock User]

def trim(s):

    if s[:1] ==' ':

        return trim(s[1:])

    elif s[-1:] ==' ':

        return trim(s[:-1])

    elif (s[:1]==' ' and s[-1:])==' ':

        return trim(s[1:-1])

    return s

#测试

if trim('hello ') !='hello':

    print('测试失败1')

elif trim(' hello') != 'hello':

     print('测试失败2')

elif trim(' hello world ') != 'hello world':

     print('测试失败3')

elif trim('') !='':

     print('测试失败4')

elif trim(' ') !='':

     print('测试失败5')

else:

     print('测试成功')


  • 1

Reply