Celtic_horizon (1) [Avatar] Offline
#1
I keep getting this error when doing the code on page 41!

Traceback (most recent call last):
line 23, in <module>
if (player_location == wumpus_friend_location - 1 or
TypeError: unsupported operand type(s) for -: 'list' and 'int'
*****************************************************************************************************
COPY OF WHAT I HAVE TYPED TO PROGRAM


if (player_location == wumpus_location - 1 or
player_location == wumpus_location + 1):
print "I smell a wumpus!"

if (player_location == wumpus_friend_location - 1 or
player_location == wumpus_friend_location + 1):
print "I smell an even stinkier wumpus!"

*****************************************************************************************************

Tried number of things can't seem to get it to work using Python 2.7.3

Message was edited by:
Celtic_horizon
anthony.briggs (30) [Avatar] Offline
#2
Re: Listing 2.3
Hi Celtic,

The specific error that you're getting is cause by trying to subtract an integer from a list. If you try to type something like this in a python prompt:

>>> [1, 2, 3] - 1

you'll get the same error.

Somewhere else in your program, the wumpus_friend_location has been set to a list. If you can find that and fix it (in that listing I've got wumpus_friend_location = choice(cave_numbers)), the code that you've posted should work.