使用If条件时Python中出现NoneType错误

2024-10-03 17:20:37 发布

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

我很难让python中的一个函数正常工作。我的函数代码如下:

def checkBlackjack(value, pot, player, wager):
    if (value == 21):
        print("Congratulations!! Blackjack!!")
        pot -= wager
        player += wager
        print ("The pot value is $", pot)
        print ("Your remaining balance is $",player)
        return (pot, player)

函数调用是:

potValue, playerBalance = checkBlackjack(playerValue, potValue, playerBalance, wager)

我得到的错误是:

potValue, playerBalance = checkBlackjack(playerValue, potValue, playerBalance, wager)
TypeError: 'NoneType' object is not iterable

由于错误说明无法迭代,因此我不确定如何将其与使用if条件联系起来。你知道吗

任何帮助都将不胜感激。谢谢!你知道吗


Tags: 函数代码ifisvaluedef错误player
2条回答

下面是这个问题的MCVE

>>> a, b = None
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    a, b = None
TypeError: 'NoneType' object is not iterable

在这一点上,问题应该是清楚的。如果没有,可以在手册中查找多个作业。你知道吗

只有在满足函数中的条件时才返回某些内容,否则函数默认返回None,然后尝试将None解压为两个值(变量)

相关问题 更多 >