使用Python中的If-Else Statment的范围功能

发布于 2025-02-10 19:17:02 字数 238 浏览 1 评论 0原文

当我输入时 45 200 为什么我没有
原因是if-else语句即将到来 但是我不知道为什么

T = int(input("i"))
for _ in range(T):
    X,Y = map (int, input().split(" "))
    if Y in  (X, X+200):
        print("yes")
    else:
        print("no")

when I enter
45 200
why I am getting no
and the reason is the if-else statement is coming false
but I don't know why

T = int(input("i"))
for _ in range(T):
    X,Y = map (int, input().split(" "))
    if Y in  (X, X+200):
        print("yes")
    else:
        print("no")

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

弥繁 2025-02-17 19:17:02

如果y在(x,x+200)中将检查y是否存在于元组中,由值xx+ 200。您可能正在寻找python /a>函数。

如果y在范围内(x,x+200)应该做您需要的事情。

if Y in (X,X+200) will check if Y exists in the tuple consisting of the values X and X+200. You might be looking for the python range function.

if Y in range(X,X+200) should do what you need.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文