Python中的错误:TypeError:unorderable类型:str()< INT()

时间:2017-10-11 03:51:46

标签: python

我正在制作数字猜谜游戏,我不知道如何

  

TypeError:unorderable类型:str()< INT()

import random

Randomnumber= random.randint(-10,10)

while -10 < Randomnumber < 10:

    print("Guess the number")
    answer= input("What do you think the number is? ")
    print(answer)
    if Randomnumber == answer:
        print("Correct!")
    elif answer < Randomnumber:
        print("Your answer is smaller than the actual value")
    else:
        print("Your answer is bigger than the actual value")

1 个答案:

答案 0 :(得分:0)

试试这个:

import random

Randomnumber= random.randint(-10,10)

while -10 <= Randomnumber <= 10:

    print("Guess the number")
    answer= input("What do you think the number is? ")
    print(answer)
    if Randomnumber == answer:
        print("Correct!")
        break
    elif answer < Randomnumber:
        print("Your answer is smaller than the actual value")
    else:
        print("Your answer is bigger than the actual value")

输入法请求输入后,也不要在单引号中输入项目。 您只需输入数字,然后按Enter键即可。如果您在单引号或双引号中输入数字,则其类型将从数字变为字符串,并且比较将失败。