语法练习:without_end
迪丽瓦拉
2024-03-28 02:45:54
0

语法练习:without_end

题目:without_end

Given a string, return a version without the first and last char, so “Hello” yields “ell”. The string length will be at least 2.

without_end(‘Hello’) → ‘ell’
without_end(‘java’) → ‘av’
without_end(‘coding’) → ‘odin’

我的解答:

def without_end(str):if len(str) <= 2:return ""else:return str[1:-1]

Expected Run
without_end(‘Hello’) → ‘ell’ ‘ell’ OK
without_end(‘java’) → ‘av’ ‘av’ OK
without_end(‘coding’) → ‘odin’ ‘odin’ OK
without_end(‘code’) → ‘od’ ‘od’ OK
without_end(‘ab’) → ‘’ ‘’ OK
without_end(‘Chocolate!’) → ‘hocolate’ ‘hocolate’ OK
without_end(‘kitten’) → ‘itte’ ‘itte’ OK
without_end(‘woohoo’) → ‘ooho’ ‘ooho’ OK
other tests
OK

All Correct

相关内容