Challenge - 5 Problems
String Mastery Badge
Get all challenges correct to earn this badge!
Test your skills under time pressure!
โ Predict Output
intermediate2:00remaining
Output of repeated string concatenation
What is the output of this Python code?
Python
s = 'ab' result = s * 3 + 'cd' print(result)
Attempts:
2 left
๐ก Hint
Remember that multiplying a string repeats it, and + adds strings together.
โ Incorrect
The string 'ab' repeated 3 times is 'ababab'. Adding 'cd' at the end gives 'abababcd'.
โ Predict Output
intermediate2:00remaining
Result of mixed string operations
What does this code print?
Python
a = 'x' b = 'y' print((a + b) * 2)
Attempts:
2 left
๐ก Hint
The parentheses affect the order of operations.
โ Incorrect
The expression (a + b) creates 'xy'. Multiplying by 2 repeats it twice: 'xyxy'.
โ Predict Output
advanced2:00remaining
Output of string repetition with variables
What is the output of this code?
Python
word = 'go' count = 4 print(word * count + word)
Attempts:
2 left
๐ก Hint
Multiplying a string by a number repeats it that many times.
โ Incorrect
word * count repeats 'go' 4 times: 'gogogogo'. Adding 'go' once more results in 'gogogogogo'.
โ Predict Output
advanced2:00remaining
String concatenation with different types
What happens when you run this code?
Python
s = 'num' n = 3 print(s + n * 2)
Attempts:
2 left
๐ก Hint
You cannot add a string and an integer directly.
โ Incorrect
Trying to add a string and an integer causes a TypeError in Python.
๐ง Conceptual
expert3:00remaining
Understanding string repetition and concatenation order
Given the code below, what is the value of variable
result?Python
result = 'a' + 'b' * 2 + 'c' * 3
Attempts:
2 left
๐ก Hint
Multiplication repeats the string before concatenation.
โ Incorrect
The code repeats 'b' twice to get 'bb' and 'c' three times to get 'ccc'. Adding 'a' at the start results in 'abbccc'.