return 'Hey! I am '+self.name+', I am '+self.color+' and I appeared in '+str(self.year)
return 'Hey! I am '+self.name+', I am '+self.color+' and I appeared in '+str(self.year)
def be_painted( self, new_color ):
def be_painted( self, new_color ):
self.color = new_color
self.color = new_color
def love( self, other_car ):
def love( self, other_car ):
return self.name+' is in love with '+other_car.name
return self.name+' is in love with '+other_car.name
```
```
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
```
flash = Car( 'Flash McQueen', 'red', 2006 )
flash = Car( 'Flash McQueen', 'red', 2006 )
flash.present()
flash.present()
```
```
%% Output
'Hey! I am Flash McQueen, I am red and I appeared in 2006'
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
```
flash.be_painted( 'purple' )
flash.be_painted( 'purple' )
flash.present()
flash.present()
```
```
%% Output
'Hey! I am Flash McQueen, I am purple and I appeared in 2006'
%% Cell type:markdown id: tags:
%% Cell type:markdown id: tags:
## Exercise:
## Exercise:
- define a new object of type Car with the following attributes: its name is Sally Carrera, its color is blue and it has the same year as the object my_car.
- define a new object of type Car with the following attributes: its name is Sally Carrera, its color is blue and it has the same year as the object my_car.
- call the method love of the Car class with Flash and Sally.
- call the method love of the Car class with Flash and Sally.
%% Cell type:code id: tags:
%% Cell type:code id: tags:
```
```
```
```
%% Output
'Hey! I am Sally Carrera, I am blue and I appeared in 2006'