Python Forum
Type error: '>' not supported between instances of 'NoneType' and 'int' - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Type error: '>' not supported between instances of 'NoneType' and 'int' (/thread-26349.html)



Type error: '>' not supported between instances of 'NoneType' and 'int' - spalisetty06 - Apr-29-2020

Hi All,
I am fairly a beginner to python, kindly help.

import random
randomnum = random.randint(1, 50)
print("The random number is ", randomnum)
num = int(input("Please enter a number from 1 to 50 "))
#print("The number entered is ", num)
while num != randomnum:
    if num > randomnum:
        num = print("The number entered is bigger, Please enter smaller number ", num)
    elif (num < randomnum):
        num = print("The number entered is smaller, Please enter bigger number ", num)
print("Thank you, you guessed it right")



RE: Type error: '>' not supported between instances of 'NoneType' and 'int' - buran - Apr-29-2020

1. print() function returns None, so if initial guess is incorrect, in the body of while loop you assign None to num.
2. You don't want print, you want input, like in line 4. Also apply the conversion to int.

as a side note
1. Please, always post the entire traceback that you get. We need to see the whole thing. Do not just give us the last line.
Take a time to read What to include in a post

2. as alternative to converting user input to int every time, you can convert the randomnum to str once