Solutions will be available when this assignment is resolved, or after a few failing attempts.
Make a Car with Doors!
Create a class
Car that is initialized by providing one mandatory argument:
It will also have one optional/default argument
'number_of_doors' set to be 4 if it is not received as an argument.
car1 = Car(color='blue', number_of_doors=2) print(car1.color) # 'blue' print(car1.number_of_doors) # 2 car2 = Car(color='green') # note that it is not passed `number_of_doors` argument print(car2.color) # 'green' print(car2.number_of_doors) # 4
test default num doors - Run Test
def test_default_num_doors(): car2 = Car(color='green') assert isinstance(car2, object) is True assert hasattr(car2, 'color') is True assert car2.color == 'green' assert hasattr(car2, 'number_of_doors') is True assert car2.number_of_doors == 4
test init attributes - Run Test
def test_init_attributes(): car1 = Car(color='blue', number_of_doors=2) assert isinstance(car1, object) is True assert hasattr(car1, 'color') is True assert car1.color == 'blue' assert hasattr(car1, 'number_of_doors') is True assert car1.number_of_doors == 2