Python Forum
Type error: '>' not supported between instances of 'NoneType' and 'int'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Type error: '>' not supported between instances of 'NoneType' and 'int'
#1
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")
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Wrong type error rowan_bradley 6 1,146 Aug-07-2023, 10:44 AM
Last Post: rowan_bradley
  Type Error: Unsupported Operand jhancock 2 1,068 Jul-22-2023, 11:33 PM
Last Post: jhancock
  Getting "SSL client not supported by this Python installation" error prabirsarkar 0 915 Mar-13-2023, 05:01 PM
Last Post: prabirsarkar
  'NoneType' error YL1985 9 2,369 Nov-26-2022, 08:45 PM
Last Post: Yoriz
  Python Anytree - Is not of type 'NodeMixin' error georgebijum 3 2,027 May-05-2022, 01:43 PM
Last Post: Gribouillis
  Getting 'NoneType' object has no attribute 'find' error when WebScraping with BS Franky77 2 5,166 Aug-17-2021, 05:24 PM
Last Post: Franky77
  Incorrect Type Error milkycow 4 2,828 Jun-25-2021, 06:04 AM
Last Post: milkycow
Star Type Error: 'in' object is not callable nman52 3 3,328 May-01-2021, 11:03 PM
Last Post: nman52
  Sort Function: <' not supported between instances of 'float' and 'tuple' quest 2 7,972 Apr-30-2021, 07:37 PM
Last Post: quest
  Error : "can't multiply sequence by non-int of type 'float' " Ala 3 3,023 Apr-13-2021, 10:33 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020