一张一张的单子,而我似乎无法得到缩进

2024-05-14 15:11:10 发布

您现在位置:Python中文网/ 问答频道 /正文

现在没有缩进错误:

def best_wild_hand(hand):
  #Try all values for jokers in all 5-card selections.
  blackJoker= "?B"
  redJoker = "?R"


  dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
  listofLists = []

  if blackJoker in hand:

    newHand = hand.remove(blackJoker)
    for d in dictSuit:
      listofLists.append(newHand.append(d + "S"))
    return listofLists

我试图得到一个列表,其中如果黑小丑是在手参数列表中找到,这是传递给最佳野生手方法。如果发现一只黑手,我们将其移除,并在手上附加2..13+C(牌组中所有的三叶草牌)。我试图做一个手的清单,其中包括1三叶草(所以手的清单+数控)n是一个数字2-13

我期望的输出是列表列表,每个列表中有2C…13C来代替黑色扑克

没有更多的错误,但当我在这个print语句中运行时,代码不会返回任何错误

print best_wild_hand(['6C', '7C', '8C', '9C', 'TC', '5C', '?B'])  

Tags: in列表for错误allbestprinthand
1条回答
网友
1楼 · 发布于 2024-05-14 15:11:10

编辑以匹配您的编辑

你的问题是你正在给一个方法分配一个变量。这导致变量None

>>> y = ['6C'].remove('6C')
>>> print y
None
>>> 

相反,改变

newHand = hand.remove(blackJoker)

newHand = hand
newHand.remove(blackJoker)

因此:

def best_wild_hand(hand):
  #Try all values for jokers in all 5-card selections.
  blackJoker= "?B"
  redJoker = "?R"


  dictSuit = {'2':2, '3':3, '4':4, '5':5, '6':6, '7':7, '8':8, '9':9, 'T':10, 'J':11, 'Q':12, 'K':13, 'A':14 }
  listofLists = []

  if blackJoker in hand:

    newHand = hand
    newHand.remove(blackJoker)
    for d in dictSuit:
      listofLists.append(newHand.append(d + "S"))
    return listofLists

现在当我运行你的代码时:

bash-3.2$ python safd.py
[None, None, None, None, None, None, None, None, None, None, None, None, None]
bash-3.2$ 

也许不是您想要的,但它仍在打印中

相关问题 更多 >

    热门问题