No result | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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()

25th Nov 2021, 1:11 PM
mariam elburai
4 Answers
+ 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.
25th Nov 2021, 1:27 PM
Coding Cat
Coding Cat - avatar
+ 1
thank you @coding at, I am new in python . I will use it in data analysis and machine learning
25th Nov 2021, 1:44 PM
mariam elburai
+ 1
Your class has no constructor (__init__() function).
25th Nov 2021, 6:46 PM
Simon Sauter
Simon Sauter - avatar
+ 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.
25th Nov 2021, 6:58 PM
Coding Cat
Coding Cat - avatar