我正在尝试学习python(我的VBA背景)购买黑杰克游戏作为教学练习。
我做了一些关于传递多个参数的搜索,但我真的不明白我在解释的方式中找到了什么。
查看最后一个名为'hand'的函数,我正在尝试使用三个单独的值作为前一个函数的'return'传递。
我收到以下错误:
Traceback (most recent call last):
File "decky15.py", line 56, in <module>
print hand(deal(shuffle(load_deck())))
TypeError: hand() takes exactly 3 arguments (1 given)
我做错了什么?我怎样才能更有效率?对解决方案或阅读材料的任何建议都非常感谢。
import random
def load_deck():
suite = ('Spades', 'Hearts', 'Diamonds', 'Clubs')
rank = ('2', '3', '4', '5', '6', '7', '8', '9', '10', "Jack", "Queen", "King", "Ace")
full_deck = {}
i = 0
for s in suite:
for r in rank:
full_deck[i] = "%s of %s" % (r, s)
i += 1
return full_deck
def pick_item(dict_in_question):
card_key = random.choice(dict_in_question.keys())
card = dict_in_question[card_key]
del dict_in_question[card_key]
return card
def shuffle(dict_in_question): #takes a dictionary as an argument and shuffles it
shuff_dict = {}
n = len(dict_in_question.keys())
for i in range(0, n):
shuff_dict[i] = pick_item(dict_in_question)
return shuff_dict
def deal(dict_in_question):
dealer ={}
player = {}
for i in range (2):
player[i] = pick_item(dict_in_question)
dealer[i] = pick_item(dict_in_question)
return (player, dealer, dict_in_question)
def hand(player, dealer, dict_in_question):
print"Here are the opening hands:"
print"Dealer: %s" % dealer(1)
print" - " * 10
print"Your hand:"
print"%s" % player[0]
print"%s" % player[1]
return 0
print hand(deal(shuffle(load_deck()))) #changed to: hand(*deal(shuffle(load_deck())))