我的代码在第二次迭代后出现错误,但我无法检测到问题。返回报告: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
您的错误发生在循环开始后,即您没有打印
type()
的print()
返回None
。。。我认为你不想要print(int(input())
相关问题 更多 >
编程相关推荐