Python 未知语法错误-大于或等于

Python 未知语法错误-大于或等于,python,syntax-error,Python,Syntax Error,我正在做一个小测验来帮助我复习天文学,但即使我输入的代码正确,还是出现了这个错误: What is the diameter of the Earth? 13000 Traceback (most recent call last): File "C:/Users/reddo/Documents/Python stuff/Astronomy quiz.py", line 19, in <module> elif answer1 >= 13001:

我正在做一个小测验来帮助我复习天文学,但即使我输入的代码正确,还是出现了这个错误:

What is the diameter of the Earth? 13000
Traceback (most recent call last):
   File "C:/Users/reddo/Documents/Python stuff/Astronomy quiz.py", line 19, in <module>
        elif answer1 >= 13001:
    TypeError: '>=' not supported between instances of 'str' and 'int'
    >>> 
地球的直径是多少?13000 回溯(最近一次呼叫最后一次): 文件“C:/Users/reddo/Documents/Python stuff/Astronomy quick.py”,第19行,在 elif回答1>=13001: TypeError:“>=”在“str”和“int”的实例之间不受支持 >>> 下面是我如何编写代码的:

answer1 = 13000 
answer1 = input ("What is the diameter of the Earth? ")

if answer1 == 13000:
    print("Correct!")

elif answer1 >= 13001:
    print ("Incorrect!")

elif answer1 <= 12999:
    print ("Incorrect!")
answer1=13000
回答1=输入(“地球的直径是多少?”)
如果回答1==13000:
打印(“正确!”)
elif回答1>=13001:
打印(“不正确!”)

elif answer1您应该将其从字符串转换为整数

answer1 = int(input ("What is the diameter of the Earth? "))

answer1是一个字符串,因此不能将其与整数进行比较。将第二行替换为以下内容以将其转换为整数:

answer1 = int(input("What is the diameter of the Earth? "))

您正在以
str
的形式读取
输入
,因此需要先将其转换为
int
,然后在if-else中使用比较运算符。错误消息清楚地表明,您正在尝试比较字符串和int,这将永远不会起作用。“即使我正确地输入了代码,这个错误还是出现了”永远不要认为编程语言对于这样一个简单的任务来说是坏的。编程的第一条规则——这总是你的错。好吧,谢谢你的帮助,我想我只是看得不够仔细。