Greetings,

I currently am trying to learn python. I obtained the book "Hello! Python" and started reading/doing the books examples. Currently I'm on chapter 2 and I'm a bit stuck.

The book's example is to make the game "Hunt the Wumpus."

The following is the code I'm stuck on:

import random

cave_numbers = range(0,20)

caves = []

for i in cave_numbers:

caves.append([])

unvisited_caves = range(0,20)

visited_caves = [0]

unvisited_caves.remove(0)

while unvisited_caves !=[]:

if len(caves

caves[next_cave].append(i)

visited_caves.append(next_cave)

unvisited_caves.remove(next_cave)

for number in cave_numbers:

print number, ":", caves[number]

print '__________'

for i in cave_numbers:

while len(caves

for number in cave_numbers:

print number, ":". caves[number]

print '__________'

When I run the program in cmd, the bolded part pops out an error. It says "Name error: choice is not defined."

I'm guessing that I haven't defined choice before, so it doesn't know what to do with it, but I followed the book's example and it's not working. I tried defining choice as:

choice = visited_caves

but it gives me another error, "Typeerror: 'list' object is not callable.

I have no idea what to try after. Can anyone help?

I currently am trying to learn python. I obtained the book "Hello! Python" and started reading/doing the books examples. Currently I'm on chapter 2 and I'm a bit stuck.

The book's example is to make the game "Hunt the Wumpus."

The following is the code I'm stuck on:

import random

cave_numbers = range(0,20)

caves = []

for i in cave_numbers:

caves.append([])

unvisited_caves = range(0,20)

visited_caves = [0]

unvisited_caves.remove(0)

while unvisited_caves !=[]:

**i = choice(visited_caves)**if len(caves

*) >= 3:*

continue

next_cave = choice(unvisited_caves)

caves.append(next_cave)continue

next_cave = choice(unvisited_caves)

caves

caves[next_cave].append(i)

visited_caves.append(next_cave)

unvisited_caves.remove(next_cave)

for number in cave_numbers:

print number, ":", caves[number]

print '__________'

for i in cave_numbers:

while len(caves

*) < 3:*

passage_to = choice(cave_numbers)

caves. append(passage_to)passage_to = choice(cave_numbers)

caves

for number in cave_numbers:

print number, ":". caves[number]

print '__________'

When I run the program in cmd, the bolded part pops out an error. It says "Name error: choice is not defined."

I'm guessing that I haven't defined choice before, so it doesn't know what to do with it, but I followed the book's example and it's not working. I tried defining choice as:

choice = visited_caves

but it gives me another error, "Typeerror: 'list' object is not callable.

I have no idea what to try after. Can anyone help?