+ 1

if statement doesn’t work

I wanna get some data which match the given condition. But the print shows that all rows ran in if statements. How did that run like this?

24th Apr 2018, 3:36 AM
Ashley
9 RĂ©ponses
+ 3
@Ace seems to be right. And the if statement expressions seem to be guaranteed to evaluate to true. I feel like the statement should be if (((114.028 <= old_matrix[row,1]) AND (old_matrix[row,1]) <= 114.029)) OR ((22.5555 <= (old_matrix[row,2]) AND (old_matrix[row,2] <= 22.5565))): Which means if row 1 is between 114.028 and 114.029 OR If row 2 is between 22.5555 and 25.5556 Then do something Before it was saying if row1 is below or equal to X or above or equal to (X+.001) [Which is almost always true unless row1 is between 114.0281 and 114.0289] AND Row2 similarly matches criteria that is almost always true then do something Depending on the intended outcome of the code, but I am guessing a human language, like English caused the logic operators And/ Or to be written in the wrong place leading to a result opposite of the desired outcome https://code.sololearn.com/cadBe1XJhwde/?ref=app
24th Apr 2018, 4:26 AM
SQrL
SQrL - avatar
+ 1
https://code.sololearn.com/chxin0AGpcxw/?ref=app
24th Apr 2018, 4:25 AM
Ashley
+ 1
@SQrl that’s the problem! thx~â˜ș
24th Apr 2018, 4:43 AM
Ashley
+ 1
you must give the code along with your question
30th Apr 2018, 6:16 AM
Farhan Javed
Farhan Javed - avatar
0
def velocity_cal(old_file,new_file): with open(old_file,'r') as old_csvFile: old_matrix = numpy.loadtxt(old_csvFile, delimiter=",", skiprows=0) rows = len(old_matrix) new_csvFile = open(new_file, 'w') writer = csv.writer(new_csvFile) for row in range(0,65500,1): if (((114.028 <= old_matrix[row,1]) or (old_matrix[row,1]) <= 114.029) and (22.5555 <= (old_matrix[row,2]) or (old_matrix[row,2] <= 22.5565))): print(row) writer.writerow(old_matrix[row,1]) row = row + 65500 rows = rows - 65500
24th Apr 2018, 3:39 AM
Ashley
0
That doesn’t work😭but thk u very much
24th Apr 2018, 4:15 AM
Ashley