Challenge - 5 Problems
String Transformation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of string strip and replace
What is the output of this Python code?
Python
text = " Hello, World! " result = text.strip().replace(",", "") print(result)
Attempts:
2 left
๐ก Hint
strip() removes spaces at start and end; replace() removes commas.
โ Incorrect
strip() removes spaces at both ends, then replace removes commas inside the string.
โ Predict Output
intermediate2:00remaining
Result of string split and join
What is the output of this code?
Python
sentence = "Python is fun" words = sentence.split() result = "-".join(words) print(result)
Attempts:
2 left
๐ก Hint
split() breaks string into words; join() connects them with dashes.
โ Incorrect
split() creates ['Python', 'is', 'fun'], join connects with '-' producing 'Python-is-fun'.
โ Predict Output
advanced2:00remaining
Output of string formatting with f-string
What does this code print?
Python
name = "Alice" age = 30 print(f"Name: {name.upper()}, Age: {age + 5}")
Attempts:
2 left
๐ก Hint
upper() makes name uppercase; age + 5 adds 5 to age.
โ Incorrect
name.upper() converts 'Alice' to 'ALICE'; age + 5 equals 35.
โ Predict Output
advanced2:00remaining
Result of chained string methods
What is printed by this code?
Python
text = " python Programming " result = text.strip().capitalize().replace("programming", "Coding") print(result)
Attempts:
2 left
๐ก Hint
strip() removes spaces, capitalize() makes first letter uppercase, replace() swaps words.
โ Incorrect
strip() removes spaces -> 'python Programming', capitalize() makes first letter uppercase and rest lowercase -> 'Python programming', replace swaps 'programming' with 'Coding'.
โ Predict Output
expert3:00remaining
Output of complex string slicing and methods
What is the output of this code?
Python
s = "DataScience" result = s[1:9:2].lower() + s[-3:].upper() print(result)
Attempts:
2 left
๐ก Hint
Slice with step 2 from index 1 to 9: indices 1('a'),3('a'),5('c'),7('e') -> 'aace'.lower(), then add last 3 uppercase.
โ Incorrect
s[1:9:2] is 'aace' (indices 1:a, 3:a, 5:c, 7:e), lower() makes 'aace', s[-3:] is 'nce', upper() makes 'NCE', combined 'aaceNCE'.