ACTIVITY 42 / 50
Try as many times as you needAn object takes action
Let’s understand
A function inside a class is a method. The first parameter of a regular instance method is self. In bot.charge(), Python supplies bot as self automatically. A method can change that object’s data.
Listen to the explanation
Example
# method: def charge(self):Add charge to increase self.energy by 5. Create a robot with energy 0, call charge and print its energy.
I need a hint
Indent the method inside the class, and its body one level further.
How to find an error
- Read the last line of the error message.
- Find the indicated line. Check quotes, parentheses and indentation.
- Change one thing and run again.
main.py
4 spaces
Your draft stays in this browser.
Result
PythonYour program’s output will appear here. Click Run.
Мой профиль