What's wrong? ( a code from medium post ) | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
0

What's wrong? ( a code from medium post )

class Vehicle: def __init__(self, number_of_wheels,type_of_tank, seating_capacity,maximum_velocity): self.number_of_wheels = number_of_wheels self.type_of_tank = type_of_tank self.seating_capacity = seating_capacity self.maximum_velocity = maximum_velocity @property def number_of_wheels(self): return self.number_of_wheels @number_of_wheels.setter def set_number_of_wheels(self,number): self.number_of_wheels = number tesla_model_s = Vehicle(4,'electric',5,250) print(tesla_model_s.number_of_wheels) tesla_model_s.number_of_wheels = 2 print(tesla_model_s.number_of_wheels) https://code.sololearn.com/cdPUy5h3veX4/#py Shows AttributeError: Traceback (most recent call last): File "..\Playground\", line 18, in <module> tesla_model_s = Vehicle(4,'electric',5,250) File "..\Playground\", line 4, in __init__ self.number_of_wheels = number_of_wheels AttributeError: can't set attribute

6th Dec 2018, 5:17 AM
Tincture
5 Respostas
+ 1
6th Dec 2018, 11:13 AM
MBZH31
MBZH31 - avatar
+ 5
https://code.sololearn.com/c3kmgg5zW0V6/?ref=app
6th Dec 2018, 5:56 AM
Rstar
Rstar - avatar
0
Thanks Rstar What's with the "_" ? Why we have to add that?
6th Dec 2018, 6:32 AM
Tincture
0
Rstar , your code run but you don't use the setter. Why ?
6th Dec 2018, 6:34 AM
MBZH31
MBZH31 - avatar