Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
What is the output of this string slicing code?
Consider the following Python code that slices a string. What will be printed?
Python
text = "Programming" print(text[3:8])
Attempts:
2 left
💡 Hint
Remember that string slicing includes the start index but excludes the end index.
✗ Incorrect
The slice text[3:8] starts at index 3 ('g') and goes up to but not including index 8 ('i'), so it includes characters at indices 3,4,5,6,7 which form 'gramm'.
❓ Predict Output
intermediate2:00remaining
What does this code print with string methods?
What is the output of this Python code that uses string methods?
Python
s = " Hello World " print(s.strip().lower().replace(' ', '_'))
Attempts:
2 left
💡 Hint
strip() removes spaces at both ends, lower() makes all letters lowercase, replace() changes spaces inside the string.
✗ Incorrect
strip() removes leading and trailing spaces, lower() converts all letters to lowercase, and replace(' ', '_') changes spaces to underscores, resulting in 'hello_world'.
❓ Predict Output
advanced2:00remaining
What is the output of this multiline string and escape sequence code?
What will this Python code print?
Python
text = '''Line1\nLine2\tTabbed''' print(text)
Attempts:
2 left
💡 Hint
Triple quotes preserve backslashes as literal characters unless raw strings are used.
✗ Incorrect
Using triple quotes with normal string (not raw) and escaped backslashes means the string contains literal backslash characters followed by n and t, so print outputs them as \n and \t.
❓ Predict Output
advanced2:00remaining
What is the output of this f-string with expressions?
What will this Python code print?
Python
name = "Alice" age = 30 print(f"Name: {name.upper()}, Age next year: {age + 1}")
Attempts:
2 left
💡 Hint
f-strings evaluate expressions inside curly braces before printing.
✗ Incorrect
name.upper() converts 'Alice' to 'ALICE', and age + 1 calculates 31, so the output is 'Name: ALICE, Age next year: 31'.
❓ Predict Output
expert3:00remaining
What is the output of this complex string manipulation code?
What will this Python code print?
Python
s = "abracadabra" result = ''.join([c.upper() if i % 2 == 0 else c for i, c in enumerate(s)]) print(result)
Attempts:
2 left
💡 Hint
The code changes characters at even positions to uppercase and leaves odd positions unchanged.
✗ Incorrect
enumerate gives index and character; for even indices (0,2,4...), character is uppercased; for odd indices, character stays the same. So the output is 'AbRaCaDaBrA'.