TypeError: '<=' not supported between instances of 'str' and 'int'
input()
by default takes the input in form of strings.
if (0<= vote <=24):
vote takes a string input (suppose 4
,5
,etc) and becomes uncomparable.
The correct way is: vote = int(input("Enter your message")
will convert the input to integer (4
to 4 or 5
to 5 depending on the input)
If you're using Python3.x input
will return a string,so you should use int
method to convert string to integer.
Python3 Input
If the prompt argument is present, it is written to standard output without a trailing newline. The function then reads a line from input, converts it to a string (stripping a trailing newline), and returns that. When EOF is read, EOFError is raised.
By the way,it's a good way to use try
catch
if you want to convert string to int:
try:
i = int(s)
except ValueError as err:
pass
Hope this helps.
Change
vote = input('Enter the name of the player you wish to vote for')
to
vote = int(input('Enter the name of the player you wish to vote for'))
You are getting the input from the console as a string, so you must cast that input string to an int
object in order to do numerical operations.