Python 3.x Uno游戏的函数(Python)

Python 3.x Uno游戏的函数(Python),python-3.x,Python 3.x,如何编写canPlay函数?如果此卡上可以玩其他游戏,则返回true,反之亦然 class UnoCard: def __init__(self, color, number): self.Color = color self.Number = number def __str__(self): if self.Color == 0: return "Blue " + str(self.Number)

如何编写canPlay函数?如果此卡上可以玩其他游戏,则返回true,反之亦然

class UnoCard:
    def __init__(self, color, number):
        self.Color = color
        self.Number = number

    def __str__(self):
        if self.Color == 0:
            return "Blue " + str(self.Number)
        if self.Color == 1:
            return "Green " + str(self.Number)
        if self.Color == 2:
            return "Red " + str(self.Number)
        if self.Color == 3:
            return "Yellow " + str(self.Number)

    ##def canPlay(self, other):

好的,我知道了。我昨晚应该喝杯咖啡


您能提供一些关于您需要帮助的部件的更多信息或提出一个具体问题吗?def canPlay(self,other):如果此卡上可以使用other,则返回true,反之亦然。我不知道如何编写这个函数?你在努力解决哪一部分?如何比较卡片?例如:地面上的绿色1。我可以玩绿色(1,2,3,…,9)或蓝色1,红色1,黄色1。我怎么检查这个?你能不能检查一下颜色或数字是否相同?
def canPlay(self, other):
    if (self.Color == other.Color) or (self.Number == other.Number):
        return True
    else:
        return False