← back to unit
Easy
# basics variables
Shortcut Assignment: += -= *= /=
A very common pattern is changing a variable based on its own current value:
score = 10
score = score + 5
Python has a shortcut for this: +=. It means "add this to what's already there":
score = 10
score += 5
print(score)
prints: 15. The same shortcut works for -=, *=, and /=.
Your turn: read a starting number into total. Use += to add 10 to it, then use *= to multiply it by 2. Print the final value.
💡 need a hint?
pyb-var-compound-assign.py🔒 given lines are locked — write your code in between
loading...