Hi All ,
I am new to Python and i have written the below code where a child class inherits from the parent class
but when i call any method of the parent class from a instance of the child class i get the error as mentioned below :-
My Code :-
When i run like this i get the message as below where i have defind all the methods in the parent class
one_pound=Pound()
?
I am new to Python and i have written the below code where a child class inherits from the parent class
but when i call any method of the parent class from a instance of the child class i get the error as mentioned below :-
My Code :-
import random class Coin: def __init__(self, rare=False,clean=True,heads= True,**kwargs): for key,value in kwargs.items(): setattr(self,key,value) print("Hi how are you ?") self.is_rare = rare self.is_clean=clean self.heads=heads if self.is_rare: self.value=self.original_value*1.25 else: self.value=self.original_value if self.is_clean: self.color=self.clean_color else: self.color=self.rusty_color def rust(self): self.color=self.rusty_color def clean(self): self.color=self.clean_color #def __del__(self): #print("Coint Spent!") def flip(self): heads_options =[True, False] choice = random.choice (heads_options) self.heads= choice class Pound(Coin): def __init__(self): data = { "original_value": 1.00, "clean_color": "gold", "rusty_color":"greenish", "num_edges":1, "diameter":22.5, "thickness":3.15, "mass":9.5 } super().__init__(**data)*************************
When i run like this i get the message as below where i have defind all the methods in the parent class
one_pound=Pound()
?
Error:>>> one_pound.color
'gold'
>>> one_pound.rust()
Traceback (most recent call last):
File "<pyshell#173>", line 1, in <module>
one_pound.rust()
AttributeError: 'Pound' object has no attribute 'rust'