Neural Sync Active
jan-2026-python-week-7-strings-2
Registry Synced
jan-2026-python-week-7-strings-2
576 words
3 min read
Strings 2
Course: Jan 2026 - Python
Strings 2
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
2/2 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.
Check if an even-length string has A or a in the second half**
Given an even-length string
s, check if the second half contains the character "a" or "A". Return True if it does, otherwise return False.Example
s = "abcDef"
The second half is "Def", which does not contain "a" or "A", so the result is
False.Template Code(Click to Expand)
def has_a_in_second_half(s: str) -> bool: ''' Given an even-length string, check if the second half contains the character "a" or "A". Arguments: s: str - an even-length string. Return: bool - True if "a" or "A" is found in the second half, else False. ''' ...
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:
texts = "HelloWorld" is_equal( has_a_in_second_half(s), False )
Case 1
Expected Output:
textFalse
Case 1
Actual Output:
textFalse
Case 2
Input:
texts = "whenwhat" is_equal( has_a_in_second_half(s), True )
Case 2
Expected Output:
textTrue
Case 2
Actual Output:
textTrue
Case 3
Input:
texts = "whenWHAT" is_equal( has_a_in_second_half(s), True )
Private Tests ( 2/2 )
Case 1
Input:
texts = "first-half" is_equal( has_a_in_second_half(s), True ) s = "half-first" is_equal( has_a_in_second_half(s), False ) s = "thisthAt" is_equal( has_a_in_second_half(s), True )
Case 1
Expected Output:
textTrue False True
Case 1
Actual Output:
textTrue False True
Case 2
Input:
texts = "concatenation" is_equal( has_a_in_second_half(s), True ) s = "BANANA" is_equal( has_a_in_second_half(s), True ) s = "APPLETON" is_equal( has_a_in_second_half(s), False )
Case 2
Expected Output:
textTrue True False
Case 2
Actual Output:
textTrue True False
💻 IITM Official Solution
pythondef has_a_in_second_half(s: str) -> bool: ''' Given an even-length string, check if the second half contains the character "a" or "A". Arguments: s: str - an even-length string. Return: bool - True if "a" or "A" is found in the second half, else False. ''' mid = len(s) // 2 return 'a' in s[mid:] or 'A' in s[mid:] # alternate way # return 'a' in s[mid:].lower()d
💻 My Submitted Code
pythondef has_a_in_second_half(s: str) -> bool: # Find the midpoint mid = len(s) // 2 # Slice the second half second_half = s[mid:] # Check for 'a' or 'A' in the sliced part # A more concise way: 'a' in second_half.lower() return 'a' in second_half or 'A' in second_half