如何测试多种条件(经度和纬度)?

问题描述 投票:-1回答:2

所以我试图分析来自特定时区的推文情绪值。我正在尝试检查具有某些经度和纬度坐标的特定时区。如何在if语句中测试多个条件?或者在for循环中?我是否放括号或东西?

 for line in infile:
        line=line.rstrip()
        words=line.split()
        firststriplat=words[0].rstrip(",")
        lat=firststriplat.lstrip("[")
        lat=float(lat)
        long=words[1].rstrip("]")
        long=float(long)
        easternlat=lat>=24.660845 and lat=<49.189787
        easternlong=long>=-87.518395 and long=<-67.444574
        if easternlat and easternlong:
python condition
2个回答
1
投票

在Python中,您可以执行以下操作来检查变量是否在特定范围内:

if (24.660845 <= lat <= 49.189787) and (-87.518395 <= long <= -67.444574):
    pass

0
投票

使用支架,你正在测试什么类型的条件?,即多少

例如,如果您有多个>和==,

你可以做点什么。

(Con A == con B)和(conC == conD)

© www.soinside.com 2019 - 2024. All rights reserved.