jeudi 26 avril 2018

if statement activates even if conditions are not met [on hold]

light = int(input("Please enter a number for light x:")), int(input("Please enter a number for light y:"))

thor = int(input("Please enter a number for thor x:")), int(input("Please enter a number for thor y:"))

longitude, latitude = thor
longitudel, latitudel = light
e = (1,0)
s = (0,1)
n = (0,-1)
w = (-1,0)
se = (1,1)
nw = (-1,-1)
ne = (1,-1)
sw = (-1,1)

while thor != light:
    if thor > (40,40) or thor < (-40,-40):
        break
    elif longitude > longitudel and latitude == latitudel: #e
        thor = tuple(sum(x) for x in zip(e + thor))
    elif latitude > latitudel and longitude == longitudel:#s
        thor = tuple (sum(x) for x in zip(s + thor))
    elif latitude < latitudel and longitude == longitudel:#n
        thor = tuple(sum(x)for x in zip(n + thor))
    elif longitude < longitudel and latitude == latitudel:#w
        thor = tuple(sum(x)for x in zip(w , thor))
    elif longitude and latitude < longitudel and latitudel:#se
        thor = tuple(sum(x)for x in zip(se , thor))
    elif longitude and latitude > longitudel and latitudel:#nw
        thor = tuple(sum(x)for x in zip(nw , thor))
    elif longitude > longitudel and latitude < latitudel:#ne
        thor = tuple(sum(x)for x in zip(ne , thor))
    elif longitude < longitudel and latitude > latitudel:  # sw
        thor = tuple(sum(x)for x in zip(sw , thor))
    print (thor)

I don't understand why the elif statements activate even if conditions are not met and its normally the se, nw, etc conditions rather then n, e, w. Can someone please explain what im doing wrong ?

Aucun commentaire:

Enregistrer un commentaire