[Tutor] Don't Understand Problem
kcberry
kcberry07 at yahoo.com
Thu Feb 26 05:30:38 CET 2015
So I am new to this, and I have a book call /Hello Python by Anthony Briggs/.
It is a good book but it is using Python 2 I think and I can't get my code
to work. I get an "AttributeError: 'range' object has no attribute
'remove'". I have tried to look it up on the web with no luck. Can someone
help me understand this .
**********
#Setting up the cave
from random import choice
cave_numbers = range(0,20)
caves = []
for i in cave_numbers:
caves.append([])
#Setting up cave network
unvisited_caves = range(0,20)
current = 0
visited_caves = [0]
*unvisited_caves.remove(0)*
#Main loop of linking cave network
while unvisited_caves != []:
#Picking a random visited cave
i = choice(visited_caves)
if len(caves[i]) >= 3:
continue
#link to unvisited caves
next_cave = choice(unvisited_caves)
caves[i].append(next_cave)
caves[next_cave].append(i)
#Marking cave as visited
visited_caves.append(next_cave)
*unvisited_caves.remove(next_cave)*
#Progress report
for number in cave_numbers:
print( number, ":", caves[number])
print('----------')
for i in cave_numbers:
while len(caves[i]) < 3:
passage_to = choice(cave_numbers)
caves[i].append(passage_to)
for number in cave_numbers:
print(number, ":", caves[number])
print('---------')
print(caves)
--
View this message in context: http://python.6.x6.nabble.com/Don-t-Understand-Problem-tp5087587.html
Sent from the Python - tutor mailing list archive at Nabble.com.
More information about the Tutor
mailing list