The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

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.