[Tutor] robots question
Peter Otten
__peter__ at web.de
Thu Sep 16 18:10:13 CEST 2010
Roelof Wobben wrote:
> As a exercise from this book ( Thinking like a computer scientist ) I have
> to make this programm on this
> page(http://openbookproject.net/thinkcs/python/english2e/ch12.html)
> Exercise 11
> def check_collisions(robots, junk, player):
> defeated = check_collisions(robot, player, junk)
Just look at the argument names: check_collisions() is probably expecting a
/list/ of robots where you are passing it a single one.
> But now Im getting this error message :
>
> Traceback (most recent call last):
> File "/root/workspace/test2/src/test.py", line 120, in <module>
> play_game(2)
> File "/root/workspace/test2/src/test.py", line 106, in play_game
> defeated = check_collisions(robot, player, junk)
> File "/root/workspace/test2/src/test.py", line 73, in check_collisions
> for thing in robots + junk:
> TypeError: can only concatenate list (not "dict") to list
>
> I understand that robots is a dict and junk is a list.
>
> Is that right ?
Yes. You are getting a dict because a single robot's state is stored in a
dictionary.
> And why does the book say that when this message is appearing.
The way the program is presented makes it hard to tell at what point your
and Eckel's idea of the script start to differ without going through the
entire chapter.
Aside: that's why real projects use version control systems. When a program
stops working after a change there is always the option to go back to the
state of the program before the bug was introduced.
Peter
More information about the Tutor
mailing list