Python - include a sum in a IF condition
Question: It's probably a dumb question but I don't manage to put a sum expression in a
If condition.  
I work on a CSV file composed of 3 rows A, B and C.

Here is my code :

    
    
    #import and export files
    
    test = "/home/julien/excel/test.csv"
    file1 = open (test, 'rb')
    
    export_test = "/home/julien/excel/export_test.csv"
    file2 = open (export_test, 'wb')
    
    reader1 = csv.reader (file1, delimiter = ';', quotechar=' ')
    writer1 = csv.writer (file2, delimiter= ';', quotechar=' ')
    
    
    #conditions on test.csv
    
    for row1 in reader1:
        A = row1[0]
        B = row1[1]
        C = row1[2]
    
        if (A + B) == C:
            writer1.writerow (["calcul ok"])
        else:
            writer1.writerow (["fail"])
    

The problem is that I only have "fail" results whereas it should not.

Could you help me ? Thanks !


Answer: Convert the strings into numbers:

    
    
    A = float(row1[0])
    B = float(row1[1])
    C = float(row1[2])
    

Or more concisely:

    
    
    A, B, C = map(float, row1[:3])
    

If your numbers are integers, replace `float` with `int`.

