import random class Coin: def __init__(self, rare=False, clean=True, **kwargs): for key,value in kwargs.items(): setattr(self,key,value) 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 * 1.0 if self.is_clean: self.color = self.original_color else: self.color = self.rusted_color def rust(self): self.color = self.rusted_color def clean(self): self.color = self.original_color def flip(self): heads_options = [True, False] choice = random.choice(heads_options) self.heads = choice def __del__(self): print(‘Coin spent!‘) class Pound(Coin): def __init__(self): data = { ‘original_value‘: 1.00, ‘original_color‘: ‘gold‘, ‘rusted_color‘: ‘greenish‘, ‘num_edge‘: 1, ‘diameter‘: 22.5, ‘thickness‘: 3.15, ‘mass‘: 9.5 } super().__init__(**data) # def __init__(self, rare=False): # self.rare = rare # if self.rare: # self.value = 1.25 # else: # self.value = 1.00 # self.value = 1.00 # self.color = ‘gold‘ # self.num_edge = 1 # self.diameter = 22.5 # self.thickness = 3.15 # self.heads = True # # def rust(self): # self.color = ‘greenish‘ # # def clean(self): # self.color = ‘gold‘ # # def flip(self): # heads_options = [True, False] # choice = random.choice(heads_options) # self.heads = choice # # def __del__(self): # print(‘Coin spent!‘)
时间: 2024-10-18 03:04:16