2016-04-15 183 views
-4

我试图找出如何使tjqk的值的10int值。有人能解释我在哪里出错了吗?酒杯的Python

class Card: 

    def __init__(self, value , suit): 
      self.value = value 
      self.suit = suit 

    def __repr__(self): 
     return "The " + self.value + " of " + self.suit 

    def intValue(self): 
     if int(self.value) > 2 or int(self.value) < 9: 
      return self.value 
     elif str(self.value) == 'a': 
      return 1 
     elif str(self.value) == 'j' or str(self.value) == 'q' or str(self.value) == 'k' or str(self.value) == 't': 
      return 10 
+4

'> 2'和'<9'省略2和10,我很确定这是有效的卡。无论如何,在我们考虑你出错的地方之前,你必须告诉我们出了什么问题。 – TigerhawkT3

+0

我在猜测最后一行的't'是10 ...? –

+1

海事组织没有理由为此做一个类,而只是使用一个元组......'(价值,诉讼)'。然后是'dict','{'a':1,'j':10,'q':10,'k':10,'t':10}'。 – Signal

回答

0

尽管我同意使用字典来表示值的意见,让我们来解决你的问题。这主要是保持简单和记住你的数据(STR)的类型,而不是随机强加str()int()通话的问题时,他们并不需要:

class Card: 

    def __init__(self, value, suit): 
     self.value = value 
     self.suit = suit 

    def __repr__(self): 
     return "The {} of {}".format(self.value, self.suit) 

    def intValue(self): 
     if self.value.isdigit(): 
      return int(self.value) 
     elif self.value == 'a': 
      return 1 
     else: 
      return 10