Challenge - 5 Problems
Variable Assignment Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ Predict Output
intermediate2:00remaining
Output of chained assignment
What is the output of this code snippet?
Python
a = b = c = 5 print(a, b, c)
Attempts:
2 left
💡 Hint
Think about how Python assigns the same value to multiple variables in one line.
✗ Incorrect
In Python, chained assignment assigns the same value to all variables. So a, b, and c all become 5.
❓ Predict Output
intermediate2:00remaining
Output after multiple assignments
What will be the value of x after running this code?
Python
x = 10 y = x x = 20 print(y)
Attempts:
2 left
💡 Hint
Remember that y gets the value of x at the time of assignment, not a reference.
✗ Incorrect
When y = x is executed, y gets the value 10. Changing x later does not affect y.
❓ Predict Output
advanced2:00remaining
Output of tuple unpacking assignment
What is the output of this code?
Python
a, b, c = 1, 2, 3 b, c = c, b print(a, b, c)
Attempts:
2 left
💡 Hint
Look carefully at how tuple unpacking swaps values.
✗ Incorrect
Initially a=1, b=2, c=3. Then b and c are swapped, so b=3 and c=2.
❓ Predict Output
advanced2:00remaining
Output of augmented assignment with mutable object
What is the output of this code?
Python
lst = [1, 2] lst2 = lst lst += [3] print(lst2)
Attempts:
2 left
💡 Hint
Remember that lst and lst2 point to the same list object.
✗ Incorrect
lst and lst2 refer to the same list. lst += [3] modifies the list in place, so lst2 also shows the change.
❓ Predict Output
expert2:00remaining
Output of variable assignment with walrus operator
What is the output of this code snippet?
Python
if (n := 5) > 3: print(n * 2) else: print(n)
Attempts:
2 left
💡 Hint
The walrus operator assigns and returns the value in the same expression.
✗ Incorrect
The walrus operator assigns 5 to n and checks if n > 3, which is true, so it prints 5*2 = 10.