TypeError:“ builtin_function_or_method”和“ int”的实例之间不支持“> =”

时间:2019-08-19 02:42:08

标签: python-3.x

当我运行以下代码时:

input("请输入1—100之间的数字:")
n = input
if n >= 1 and n <= 100:
    print("你妹好漂亮!")
else:
    print("你大爷好丑")
print("游戏结束啦!不和你玩了")


if n >= 1 and n <= 100:

我收到以下错误:

  

TypeError:'> ='在以下实例之间不受支持   'builtin_function_or_method'和'int'`

1 个答案:

答案 0 :(得分:1)

错误1: 您需要将input()值存储在容器/变量中。这就是为什么您会第一手得到错误的原因。

错误2: 看起来您正在要求用户输入整数,在这种情况下,您需要将默认的string类型转换为int()

下面的代码是您的方案的固定版本。

n = int(input("请输入1—100之间的数字:"))
if n >= 1 and n <= 100:
    print("你妹好漂亮!")
else:
    print("你大爷好丑")
print("游戏结束啦!不和你玩了")


if n >= 1 and n <= 100:
   #Your if logic goes here.