Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 蟒蛇3.3.2年龄>;=24:TypeError:无序类型:str()>;=int()_Python - Fatal编程技术网

Python 蟒蛇3.3.2年龄>;=24:TypeError:无序类型:str()>;=int()

Python 蟒蛇3.3.2年龄>;=24:TypeError:无序类型:str()>;=int(),python,Python,这就是我得到的错误: print("how old are you") age = input(">") if age >= 24: print("you are getting old") print (age) else: print("i don't care") print (age) 在Python3上,input()始终返回字符串值。使用以下命令将其转换: if age >= 24: TypeError: unorderable types: str()

这就是我得到的错误:

print("how old are you")
age = input(">")
if age >= 24:
print("you are getting old")
print (age)
else:
print("i don't care")
print (age)
在Python3上,
input()
始终返回字符串值。使用以下命令将其转换:

if age >= 24:
TypeError: unorderable types:     str() >= int()
字符串值和int不可排序:

if int(age) >= 24:

age
是一个字符串,而不是一个int。要使其成为int,请使用
int()
函数,因此:

>>> int('Why do you want to know my age?')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: invalid literal for int() with base 10: 'Why do you want to know my age?'
请注意这一行:

print("how old are you")
age = input(">")
if int(age) >= 24:
    print("you are getting old")
    print (age)
...

谢天谢地,g8真的没想到会有这么快的答案,再次感谢python 3。*输入相当于python 2.7中的原始输入。*。这可能是让你困惑的原因。
print("how old are you")
age = input(">")
if int(age) >= 24:
    print("you are getting old")
    print (age)
...
if int(age) >= 24: