why is this raising an error? (see photos please) def load_treasure_map(filename): '''(str) -> list converts content of a file to a list
why is this raising an error? (see photos please)
def load_treasure_map(filename):
'''(str) -> list
converts content of a file to a list
>>> load_treasure_map('map0.txt')
[['>', '>', '>', 'v', '.', '.', '.', '.', '.', '.'],
['.', '.', '.', 'v', '.', '.', '.', '<', '<', '.'],
['.', '.', '.', 'v', '.', '.', '.', '.', '.', '.'],
['v', '.', '.', 'v', '.', '.', '.', '.', '^', '.'],
['v', '.', '.', '>', '>', '*', '.', '.', '^', '.'],
['v', '.', '.', '.', '.', '.', '.', '.', '^', '.']]
'''
filename = "map0.txt"
map_filename = open(filename, 'r')
map_str = map_filename.read()
#check for invalid chars
for i in map_str:
if i not in chars and i not in num:
raise AssertionError('Invalid charater', i)
maplist = []
sublist = []
for i in map_str:
if i == '\n':
maplist.append(sublist)
sublist = []
else:
sublist.append(i)
temp = len(maplist[0])
for i in maplist:
if len(i)!= temp:
raise AssertionError('Invalid length')
temp = len(i)
return maplist
my_file.close()
Step by step
Solved in 2 steps