117k views
0 votes
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'

User Austria
by
6.0k points

1 Answer

4 votes

Answer:

def without_end(strg):

if len(strg)>2:

return strg[1:-1]

else:

return strg

Step-by-step explanation:

Given above is a function in Python for solving this problem, we can try different output for this program by calling this function in a print statement

print(without_end ("hello")) output ell

print(without_end ("java")) output av

print(without_end ("coding")) output odin

User Timkado
by
6.1k points