Discuss / Python / 打卡

打卡

Topic source

xlwb_Mew

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

-- coding: utf-8 --

def trim(s):

if(len(s)==0):
    return s
if(s[0]==' '):
    s=s[1:]
    s=trim(s)
if(len(s)==0):
    return s
if(s[-1]==' '):
    s=s[:-1]
    s= trim(s)
print('-',s,'-')
return s

测试:

if trim('hello ') != 'hello': print('测试失败!') elif trim(' hello') != 'hello': print('测试失败!') elif trim(' hello ') != 'hello': print('测试失败!') elif trim(' hello world ') != 'hello world': print('测试失败!') elif trim('') != '': print('测试失败!') elif trim(' ') != '': print('测试失败!') else: print('测试成功!')

轩辕诗垚

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

大佬思路好清晰,膜拜一波


  • 1

Reply