I am solving a USACO Bronze problem in Python. After writing my code and testing it, I got this error:
Traceback (most recent call last):
File "c:\Users\13579\OneDrive\Documents\cod\cont.py", line 59, in <module>
g = min(h, c)
^^^^^^^^^
TypeError: '<' not supported between instances of 'str' and 'int'
h and c are part of two for-loops (for h in canes, for c in cows)
The error states that the less than symbol cannot be used at that position, but there is no less than symbol on this line, and I don’t use it anywhere else in the code. What could cause this error?
I tried setting g to an integer by putting g = int(g) before the troublesome line, but this resulted in the same error. I changed the canes and cows lists to have integer values, but this did not change anything.
Please provide your code
To compute
min(h, c)
, Python has to compare them and it uses the<
operator for that. What are the types ofh
andc
?Are you trying to find the min between two strings? By “h in canes” do you mean it’s iterating through “canes”?
h was a string. but c was not. I see that min needs to use the < operator. Thanks!
to answer samsupertaco yes.
Show 3 more comments