0
No result
# second class class Phone: def add_color(self,color): self.color = color def add_cost(self,cost): self.cost = cost def show_color(self): return color def show_cost(self): return cost p3=Phone() p3.add_color("blue") p3.show_color()
4 odpowiedzi
+ 4
missing self in return statement:
return self.color
return self.cost
And missing print for output:
print(p3.show_color())
And wrong indentation. The last 3 lines belong all the way to the left.
+ 1
thank you @coding at, I am new in python . I will use it in data analysis and machine learning
+ 1
Your class has no constructor (__init__() function).
+ 1
Yes Simon Sauter you are right. But if you create a class without a constructor, Python automatically creates the default constructor for you. That doesn’t do anything. I think it's not an issue for a simple example like this.