python nonetype_函数在Python中返回一个NoneType?

1586010002-jmsa.png

Working on a Python project for CS1, and I have come accross a strange issue that neither I or my roomate can figure out. The general scope of the code is to fill in a grid of 0s with shapes of a certain size using numbers to fill the space, and we have to check along the way to make sure we arent putting shapes in places there there are already shapes. I have two functions here, both do virtually the same thing, but for whatever reason when falsechecker returns the list it returns it as a NoneType. Why is this happening?

def falseChecker(binList, r, c, size):

sCheck = isSpaceFree(binList, r, c, size)

if sCheck == True:

for x in range(c, c+size):

for y in range(r, r+size):

binList[x][y] = size

return binList

else:

c += 1

if c > len(binList):

c = 0

r += 1

if r > len(binList):

return binList

falseChecker(binList, r, c, size)

def iChecker(binList, blockList):

r = 0

c = 0

for i in blockList:

check = isSpaceFree(binList, r, c, i)

if check == True:

for x in range(c, c+i):

for y in range(r, r+i):

binList[x][y] = i

c += 1

if c > len(binList):

c = 0

r += 1

if r > len(binList):

return binList

else:

binList = falseChecker(binList, r, c, i)

return binList

main()

解决方案

In the case where sCheck == True is false, you don't return anything. And in Python, a function that doesn't explicitly return anything returns None.

If you were trying to recursively call yourself and return the result, you wanted this:

return falseChecker(binList, r, c, size)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值