[Tutor] Fw: Traceback

Danny Yoo dyoo at hashcollision.org
Wed Nov 19 01:29:25 CET 2014


On Tue, Nov 18, 2014 at 1:46 PM,  <niyanaxx95 at gmail.com> wrote:
> I get this message:
> Traceback (most recent call last):
>   File "C:\Program Files (x86)\Wing IDE 101
> 5.0\src\debug\tserver\_sandbox.py", line 87, in <module>
>   File "C:\Program Files (x86)\Wing IDE 101
> 5.0\src\debug\tserver\_sandbox.py", line 20, in main
>   File "C:\Program Files (x86)\Wing IDE 101
> 5.0\src\debug\tserver\_sandbox.py", line 70, in tilesForSize
> builtins.TypeError: unsupported operand type(s) for -: 'NoneType' and 'int'

Hi Niyana,

Ok, let's look at the error message a bit more closely.  It's saying:
"somewhere in tilesForSize, you're asking me to subtract a value
that's not an int."

Let's look at the definition of tilesForSize:

######################################
def tilesForSize(size) :
    pairs = int((size - tileSize) // int(2 * tileSize))
    num = int(1 + (2 * pairs))
    return num
######################################

There is only a single place where subtraction is happening here, so
we can point a finger at the sub-expression:

    size - tileSize


Assuming we can trust the error message, all we need to do now is
figure out why:

    size - tileSize

is erroneous in this context.  size is one of the parameters, and
tileSize is... I don't know what it is yet.  Global variable, perhaps?

Let's assume, for the moment, that the problem is the parameter.  (If
we guessed wrong, we'll double back and start looking at tileSize.)


You may have heard the term: "Garbage in, garbage out".  Our job now
is to look at how we got that input value, and at what point it was
garbage.


So at this point, I'd look at one of the call points of tilesForSize.
The stack trace we're looking at says that it saw a problem when
main() was calling tilesForSize, on line 20.  What does that line say?
 It's one of these lines:

    numCols = tilesForSize(roomWidth)
    numRows = tilesForSize(roomLength)

The source of the argument here is roomWidth and roomLength.  Where do
those values come from?  Reading...  ah, they come from here:

    roomWidth = getNumber(100, 500, "Enter a room width between 100
and 500: ", "")
    roomLength = getNumber(100, 450, "Enter a room length between 100
and 450: ", "")


Ok, so here's a question: does getNumber actually return a number?
Have you tested this?


More information about the Tutor mailing list