Registry Synced

jan-2026-python-week-7-strings-4

541 words
3 min read

Strings 4

Course: Jan 2026 - Python
Strings 4
Submission deadline has passed for this assignment
Due Apr 01, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:48 AM IST
Private Tests
3/3 Passed
Submitted on Apr 01, 2026 at 3:48 AM IST

**Change in eligibility criteria to write oppe2 exam: A5>=40/100 AND A6>=40/100 AND A7>=40/100 AND A8>=40/100. and becoming eligible to give the end term exam.


Remove First two and Last two Chars from a string**
Given a string s, return a new string with the first two and last two characters removed.
If the string has less than four characters return an empty string.
Example
s = 'HelloWorld'
Removing the first two and last two characters results in 'lloWor'.
Template Code(Click to Expand)


def remove_edges(s: str) -> str:
    '''
    Return a new string with the first two and last two
    characters removed from the given string.

    Arguments:
    s: str - a string.

    Return: str - a string with first and last two characters removed.
    '''
    ...


NOTE: You can use the below tools for working out and debugging. Click to open them in new tab.

Public Tests ( 3/3 )

Case 1

Input:
text
s = 'abcdef'
is_equal(
    remove_edges(s),
    'cd'
)

Case 1

Expected Output:
text
'cd'

Case 1

Actual Output:
text
'cd'

Case 2

Input:
text
s = 'abcdefghij'
is_equal(
    remove_edges(s),
    'cdefgh'
)

Case 2

Expected Output:
text
'cdefgh'

Case 2

Actual Output:
text
'cdefgh'

Case 3

Input:
text
s = 'abcd'
is_equal(
    remove_edges(s),
    '' # empty string
)

Case 3

Expected Output:
text
''

Case 3

Actual Output:
text
''

Private Tests ( 3/3 )

Case 1

Input:
text
s = 'HelloWorld'
is_equal(
    remove_edges(s),
    'lloWor'
)

Case 1

Expected Output:
text
'lloWor'

Case 1

Actual Output:
text
'lloWor'

Case 2

Input:
text
s = 'Mountain'
is_equal(
    remove_edges(s),
    'unta'
)

Case 2

Expected Output:
text
'unta'

Case 2

Actual Output:
text
'unta'

Case 3

Input:
text
s = '123456789'
is_equal(
    remove_edges(s),
    '34567'
)

Case 3

Expected Output:
text
'34567'

Case 3

Actual Output:
text
'34567'

💻 IITM Official Solution

python


def remove_edges(s: str) -> str:
    '''
    Return a new string with the first two and last two
    characters removed from the given string.

    Arguments:
    s: str - a string.

    Return: str - a string with first and last two characters removed.
    '''


    return s[2:-2]


💻 My Submitted Code

python
def remove_edges(s: str) -> str:
    # Check length constraint
    if len(s) < 4:
        return ""

    # Slice from index 2 up to the 2nd character from the end
    return s[2:-2]

Document Outline
Table of Contents
System Normal // Awaiting Context

Intelligence Hub

Navigate the knowledge graph to generate context. The Hub adapts dynamically to surface backlinks, related notes, and metadata insights.