There’s an issue with the print_results function in robot_race_functions.py that prevents the final score from being printed out. The error is stated that there is a TypeError: ‘<’ between instances of ‘Counter’ and ‘Counter’. Anyone know anything about how to solve it? I’ve posted a screenshot of the error down below
The problem is most likely with the arguments provided to the
print_results function. It looks like you provided instances of
Counter rather than the values needed. Consider the following:
>>> class Num: ... def __init__(self, value): ... self.value = value ... >>> a = Num(4) >>> b = Num(5) >>> a < b Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: '<' not supported between instances of 'Num' and 'Num' #the same error was thrown because the instances themselves cannot be compared with '<' #the values stored in the `value` property of each instance can be compared >>> a.value < b.value True
In that case, I’m not entirely sure how to fix that, since I was following the project instructions exactly.
We’ll need to see your code to be of any help.
def print_results(bot_score_data): # for score_data in bot_score_data: # print(score_data.values()) bot_score_data.sort(key=lambda b: b.score['score'], reverse = True) place = 1 print("----- RESULTS -----") for score_data in bot_score_data: print(str(place) + '. Robot: ' + str(score_data.name)) print(' ' + ' Score: ' + str(score_data.score[str(score_data.name)]) + '\n Moves: ' + str(score_data.num_moves[str(score_data.name)]) + '\n Collisions: ' + str(score_data.num_collisions[str(score_data.name)])) place += 1
Never mind I managed to fix it. Do the following at Step 9 if you get stuck
bot_scores =  # Add your code below! for bot in bots: bot_scores.append(BotScoreData(bot.name, move_counter[bot.name], collision_counter[bot.name], move_counter[bot.name] + collision_counter[bot.name]))
Glad you were able to fix it.
This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.