0
Traceback (most recent call last):
 File "main.py", line 17, in <module>
 max_height = max(botmoves)
TypeError: '>' not supported between instances of 'tuple' and 'int'

This is the error I'm trying to find the biggest value in a list but it saying something about a ">" here is my code

 from random import randint
 points = 0
 botmoves = [-1000]
 for i in range(20):
 guess = randint(0, 100)
 print('Bot',"guessed the number was", guess)
 print("The bot was",abs(guess-100),"off")
 print("The bot gets",50 - abs(guess-100),"points")
 points = 50 - abs(guess-100),"points"
 botmoves.append(points)
 max_height = max(botmoves) #this is where the error is
 print(botmoves)
asked May 11, 2022 at 14:58
2
  • Some items in botmoves are ints and others are tuples. Commented May 11, 2022 at 15:01
  • The error is pretty explanatory. It tells you that you are trying to compare tuples and integers. Your points variable, whose max value you are trying to spot, is of type List[Tuple]. You have to use a custom key= to the max function if you want to make it work for complex types. In other words, this will work if you instead use a List[int] for your botmoves var. Commented May 11, 2022 at 15:03

1 Answer 1

2

The max function needs to be able to compare values to each other, and it does that with the > operator. What the error is telling you is that there are different types of elements in the list, which cannot sensibly be compared to each other. In this case, an int and a tuple.

The reason for that is this line:

 points = 50 - abs(guess-100),"points"

The ,"points" at the end makes points into a tuple, for example (37, "points"). The parentheses are optional in many cases.

Probably that's just a copy/paste mistake from the line above, and you didn't mean to put that there:

 points = 50 - abs(guess-100)
answered May 11, 2022 at 15:01
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.