TypeError: '<' not supported between instances of 'NoneType' and 'int'
I have looked for an answer in Stack Overflow and found that I should be taking an int(input(prompt)), but that's what I am doing
def main():
while True:
vPopSize = validinput("Population Size: ")
if vPopSize < 4:
print("Value too small, should be > 3")
continue
else:
break
def validinput(prompt):
while True:
try:
vPopSize = int(input(prompt))
except ValueError:
print("Invalid Entry - try again")
continue
else:
break
This problem also comes up when migrating to Python 3.
In Python 2 comparing an integer to
None
will "work," such thatNone
is considered less than any integer, even negative ones:In Python 3 such comparisons raise a
TypeError
:you need to add a return in your function to get the number you input, otherwise it return an implicit None
or as noted in the comments, make validinput also check if it is an appropriate value
And you will notice when the function is called.
The problem is that validinput() does not return anything. You'd have to return vPopSize