0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Difficulty: 3
click for more info
No active XP Potion
Accept a Quest
Login to submit answers
Python makes reassignment easy when doing math. In JavaScript or Go, you might be familiar with the ++
syntax for incrementing a number variable by 1. In Python, we use the +=
in-place operator instead.
star_rating = 4
star_rating += 1
# star_rating is now 5
The other in-place operators work similarly:
star_rating = 4
star_rating -= 1
# star_rating is now 3
star_rating = 4
star_rating *= 2
# star_rating is now 8
star_rating = 4
star_rating /= 2
# star_rating is now 2.0
Complete the get_hurt
function. It should use the -=
in-place operator to subtract damage
from current_health
and then return the new current_health
.
You cannot use -=
in a return statement. Set the variable first, and then return it after!
Focus Editor
Alt+Shift+]
Next Tab
Alt+Shift+[
Become a member to Submit
Become a member to Run
Become a member to view solution