TaliffEd TaliffEd - 1 month ago 12
Python Question

NoneType error with lists in a while loop?

I'm writing a guessing game program, with defined functions. It asks the user to think of a number between 1 and 1000, then the program tries to guess the number in less than 15 tries. With my functions, to return multiple values in each function, I'm returning them as lists. But there's a NoneType error - here's the error message.

Traceback (most recent call last):
File "python", line 187, in <module>
File "python", line 167, in main
TypeError: 'NoneType' object is not subscriptable


Here's my code:

while opAns.lower() != "no":
FBTrcTri = guessReturn(tries, upper, lower)
feedback = FBTrcTri[0]
errorBound = FBTrcTri[1]
errorTrick = FBTrcTri[2]
tries = FBTrcTri[3]


And the function is defined here:

def guessReturn(tries, upper, lower):
while tries < 15:


errorInput = "yes"

while errorInput == "yes":
feedbackGuessVal = guesser(upper, lower)


feedback = feedbackGuessVal[0]
guessVal = feedbackGuessVal[1]


LUITri = processData(feedback, tries, upper, lower, guessVal)


lower = LUITri[0]
upper = LUITri[1]
errorInput = LUITri[2]
tries = LUITri[3]


errorBound = boundChecker(upper, lower)
errorTrick = trickChecker(upper, lower)

if errorBound == "yes":
return
elif errorTrick == "yes":
return
elif feedback == "0":
tries += 1
return


tries += 1


return [feedback, errorInput, errorBound, errorTrick, tries]

Answer
if errorBound == "yes":
    return
elif errorTrick == "yes":
    return
elif feedback == "0":
    tries += 1
    return

A return statement with no value will return None, which you are then trying to treat as a list