Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Basic Object-Oriented Python Welcome to OOP Methods

'if not' question.

does 'if self.is_moving:' also translate as 'if self.is_moving == False'? if so does that mean 'if not self.is_moving:' means 'if self.is_moving == True:'?

if this is correct why does the go(self, speed) method print when the is_moving value is False

2 Answers

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

Once an object is instantiated, the logic is synchronous. In the final addition of code, the car can only move two times before it runs out of gas!

The car uses 50 fuel each time you use gas and only has 50 fuel to start with. Note the part about use_gas().

You may want to rewrite the code a bit to make it more realistic. For example, you might want to write get_fuel() where you can accept so much gas based on how much you have in your tank.

Jeff Muday
MOD
Jeff Muday
Treehouse Moderator 28,720 Points

For the most part, the statement if self.is_moving: would mean that self.is_moving is "truthy".

In other words, it would be equivalent if self.is_moving == True:

thanks, could you explain why both methods in the video run when the if statements are asking for two different things? self.is_moving = False, so why does it run in both 'if self.is_moving:' and 'if not self.is_moving:'?