Reputation: 67
I have the following points in the cartesian plane:
points = [(4, 5), (-0, 2), (4, 7), (1, -3), (3, -2), (4, 5), (3, 2), (5, 7), (-5, 7), (2, 2), (-4, 5), (0, -2),(-4, 7), (-1, 3), (-3, 2), (-4, -5), (-3, 2), (5, 7), (5, 7), (2, 2), (9, 9), (-8, -9)]
And I want to know how many of them are in each quadrant. If x or y are 0, the point is not in any quadrant.
So far I have done this:
Q1=0
Q2=0
Q3=0
Q4=0
Any_quadrant=0
for (x,y) in points:
if (x>0 & y>0):
Q1+=1
elif (x<0 & y>0):
Q2+=1
elif (x<0 & y<0):
Q3+=1
elif (x>0 & y<0):
Q4+=1
else:
x==0 | y==0
Any_quadrant+=1
print(Q1)
print(Q2)
print(Q3)
print(Q4)
print(Any_quadrant)
But the sum of the points in each quadrant is not happening and I don't know how to make it work.
Upvotes: 0
Views: 726
Reputation: 403
Python uses and
instead of && and or
instead of ||. In python & and | are bitwise operators, not boolean operators. Furthermore else
statements do not include conditions so you need to remove that.
As a style note, in python variables should not have capital letters unless they are the names of classes or are constants.
Upvotes: 1