Learn Python 016: Coin - a project of msc, unfinished.

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Learn Python 016: Coin - a project of msc, unfinished.相关的知识,希望对你有一定的参考价值。

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!‘)

 

以上是关于Learn Python 016: Coin - a project of msc, unfinished.的主要内容,如果未能解决你的问题,请参考以下文章

nyoj 204-Coin Test (python count)

Lesson 016 —— python 元组

Python练习题 016:猴子吃桃

python016

Python入门100题 | 第016题

python数据类型-字典-016