【发布时间】:2015-12-11 08:38:29
【问题描述】:
def make_sorted_deck():
''' Return a sorted deck of cards. Each card is
represented by a string as follows:
"queen of hearts". The cards are ordered by rank and then suit within rank.
:return: The sorted deck of cards, as a list of strings
EXAMPLE: make_sorted_deck() == ['2 of spades', '2 of hearts', '2 of clubs', ..., 'ace of clubs', 'ace of diamonds'] '''
#Hint: Use the previous functions and two nested for loops.
sorted_deck = []
for i in get_ranks():
for j in get_suits():
sorted_deck.append("{0} of {1}".format(i,j))
return sorted_deck
print(make_sorted_deck())
def shuffle(deck):
''' Randomly shuffle the cards in deck into a newly created deck of cards (list).
:param: deck: A deck of cards
:return: A new list, consisting of a random shuffle of deck.
EXAMPLE: shuffle(['2 of hearts', '3 of diamonds', 'jack of spades', '2 of clubs']) could return ['jack of spades', '3 of diamonds', '2 of hearts', '2 of clubs']
#REQUIREMENTS: Please implement the following algorithm: Use a while loop to repeatedly pick a random card from deck, remove it, and add it to a newly created list. '''
如何随机播放make_sorted_deck() 创建的列表?
我知道我可以导入一个函数来洗牌,但我需要这样做的方法是取出 1 张随机牌并将其附加到一个新列表中以获得一个洗牌列表。
【问题讨论】:
-
@GingerPlusPlus 我认为两者不同。查看 OP 的结束评论