Challenge - 5 Problems
String Structure Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate1:00remaining
What is the output of this string indexing code?
Consider the string
s = 'hello'. What will print(s[1]) output?DSA Python
s = 'hello' print(s[1])
Attempts:
2 left
💡 Hint
Remember, string indexing starts at 0.
✗ Incorrect
Strings are like a list of characters. Index 0 is 'h', index 1 is 'e'. So s[1] is 'e'.
❓ Predict Output
intermediate1:00remaining
What is the output after slicing a string?
Given
s = 'datastructure', what does print(s[4:9]) output?DSA Python
s = 'datastructure' print(s[4:9])
Attempts:
2 left
💡 Hint
Slicing includes start index but excludes end index.
✗ Incorrect
Slicing from index 4 to 9 takes characters at positions 4,5,6,7,8. That is 's','t','r','u','c'.
🧠 Conceptual
advanced1:30remaining
Why are strings considered data structures?
Which of the following best explains why strings are data structures and not just plain text?
Attempts:
2 left
💡 Hint
Think about how you can access parts of a string.
✗ Incorrect
Strings hold characters in order and allow operations like indexing and slicing, which are features of data structures.
🔧 Debug
advanced1:30remaining
What error does this string operation cause?
What error will this code raise?
s = 'hello'
print(s[10])DSA Python
s = 'hello' print(s[10])
Attempts:
2 left
💡 Hint
Check if the index is within the string length.
✗ Incorrect
Index 10 is beyond the length of 'hello' (which is 5), so Python raises an IndexError.
🚀 Application
expert2:00remaining
How many items are in the resulting list after splitting?
Given
s = 'a,b,c,d', what is the length of s.split(',')?DSA Python
s = 'a,b,c,d' result = s.split(',') print(len(result))
Attempts:
2 left
💡 Hint
Splitting breaks the string at each comma.
✗ Incorrect
Splitting 'a,b,c,d' by ',' creates ['a', 'b', 'c', 'd'], which has 4 items.