. Advertisement .
..3..
. Advertisement .
..4..
I don’t know what I’m doing wrong, but I’ve already lost a couple of days struggling with this. Here is my command line:
players= [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]
vote = 0
cont = 0
while(vote >= 0 and vote <23):
vote = input('Enter the name of the player you wish to vote for')
if (0 < vote <=24):
players[vote +1] += 1;cont +=1
else:
print('Invalid vote, try again')
This returns:
TypeError: '<=' not supported between instances of 'str' and 'int'
I don’t have any experience with typeerror: ‘<‘ not supported between instances of ‘str’ and ‘int’. In this case, how should I change?
The cause: When using Python3.x, this error happens because the function gets the input and converts a line to a string and then it is returned.
Solution: To deal with this error, you need to use
int
method to transform string into integer like this:input()
defaults to strings as inputVote is a string input (suppose
4
,5
, etc.) and becomes uncomparable.The correct way to vote is
vote = input("Enter Your Message")
will convert your input to integers (4
to 4, or5
to 5, depending on which input you provide)It automatically converts the input function into a string when you use it. Here’s where you need to be:
This converts the input to an int type value