社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
私信  •  关注

Owen

Owen 最近回复了

你的x/y比较需要括号。我修改了代码,我认为它现在可以按你的预期工作了:

print("what is x")
x = int(input('> '))
print("what is y")
y = int(input('> '))
if (x > y) is True:
    print("x > y")
elif (x > y) is not True:
    print("y > x")
else:
    print("whatever")

编辑:正如其他人在评论中指出的,您不必显式地比较 x > y 。你可以这样做:

print("what is x")
x = int(input('> '))
print("what is y")
y = int(input('> '))
if x > y
    print("x > y")
elif y > x:
    print("y > x")
else:
    print("whatever")