The Great Robot Race - print_results doesn't work

Link to project:

There’s an issue with the print_results function in 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

1 Like

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

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[3].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(
      print('  ' +  '  Score: ' + str(score_data.score[str(]) + '\n    Moves: ' + str(score_data.num_moves[str(]) + '\n    Collisions: ' + str(score_data.num_collisions[str(]))
      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(, move_counter[], collision_counter[], move_counter[] + collision_counter[]))

Glad you were able to fix it.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.