我试图从输入到函数中的一只手数出每一套衣服的数量。这是我当前的代码:
def tally(h):
hands = {''}
hands.update(h)
for i in h:
if hands.get('♥'):
heart += 1
if hands.get('♣'):
club += 1
if hands.get('♦'):
diamond +=1
if hands.get('♠'):
spade += 1
suit = {
'♥':heart,
'♣':club,
'♦':diamond,
'♠':spade
}
return(suit)
但是,我一直在获取错误AttributeError:“set”对象没有属性“get”
当你做
hands = {''}
的时候,你是在做一个集,而不是一个字典。用hands = {}
替换它就可以了更多信息请参见on the python documentation
相关问题 更多 >
编程相关推荐