意外错误:“非类型”和“int”实例之间不支持“<”类型错误

2024-04-28 11:48:07 发布

您现在位置:Python中文网/ 问答频道 /正文

我的代码在第二次迭代后出现错误,但我无法检测到问题。返回报告:TypeError:“<;”在“NoneType”和“int”的实例之间不受支持 但是这两个变量是INT,代码只有在第二次迭代后才会做出这样的反应

numero = int(input('Olá. Sou seu computador...\nAcabei de pensar em um número entre 1 e 
10.\nSerá se você consegue advinhar qual foi? \nQual é seu palpite? '))
import random
sorteado = random.randint(1,11)
print(sorteado)
tot=1
print(type(sorteado))
print(type(numero))
while numero != sorteado:
    if numero < sorteado:
        numero = print(int(input('Mais...tente mais uma vez!')))
        tot+=1
    elif numero > sorteado:
        numero = print(int(input('Menos...tente mais uma vez!')))
        tot+=1
print('Parabéns! Você acertou em {} tentativas.'.format(tot))

C:\Downloads\pythonexercicios\venv\Scripts\python.exe C:/Downloads/pythonexercicios/ex058.py
Olá. Sou seu computador...
Acabei de pensar em um número entre 1 e 10.
Será se você consegue advinhar qual foi? 
Qual é seu palpite? 1
6
<class 'int'>
<class 'int'>
Mais...tente mais uma vez!3
3
Traceback (most recent call last):
  File "C:\Downloads\pythonexercicios\ex058.py", line 9, in <module>
    if numero < sorteado:
TypeError: '<' not supported between instances of 'NoneType' and 'int'

Process finished with exit code 1

Tags: 代码inputdownloadsintprintemumaseu
1条回答
网友
1楼 · 发布于 2024-04-28 11:48:07

您的错误发生在循环开始后,即您没有打印type()

print()返回None。。。我认为你不想要print(int(input())

相关问题 更多 >