写一个函数,deal(numhands,n=5,deck),它 每手牌有n张牌。在
import random # this will be a useful library for shuffling
from random import shuffle
# This builds a deck of 52 cards. If you are unfamiliar with this
# notation, check out Andy's supplemental video
# on list comprehensions (you can find the link in the
# Instructor Comments box below).
mydeck = [r+s for r in '23456789TJQKA' for s in 'SHDC']
def deal(numhands, n=5, deck=mydeck):
mynew = shuffle(deck)
if numhands*n > len(deck):
raise Exception('Not enough cards.')
hands = []
for i in range(0,numhands):
ncards = []
for j in range(0,n):
ncards.append(mynew.pop())
hands.append(ncards)
return hands
print deal(2)
我不知道这个函数有什么问题,但它总是告诉我这个错误 成交 ncards.append(我的新.pop()) AttributeError:“NoneType”对象没有属性“pop”
random.shuffle
原地洗牌它改变了原来的牌组。。。它不返回任何内容
所以只要使用
deck
相关问题 更多 >
编程相关推荐