Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Calculate variant of the numbers / TypeError: 'int' object is not callable

sorry, i know, there is a bunch of answers about that but my noobness doesnt let me understand the answer to adequate to my problem…

i get the TypeError: ‘int’ object is not callable on the line 27 (var = …)

the file data1_.txt is just 5 lines with a integer number in each line.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

can someone help me to understand why?

line_number = 0;
countline = 0;
linesum = 0;
avg = 0;
var = 0;
linelist = [];

f = open("data1_.txt", "r")

while True:
#how to count lines    
    line = f.readline()
    if line == "" :
        break
    line = line.rstrip("\n\r")
    line_number += 1
    if line != "/n":
        countline += 1
#how to list the numbers     
    x = line.strip()
    linelist.append(x)
#how to sum the numbers of the list
    linesum += int(x)*1.0
    avg = linesum/countline;

#how to calculate variant of numbers
    var = sum((y-avg) **2 for y in linelist) / countline
    
f.close()

print("number of lines:", countline)
print("the numbers:", linelist)
print("sum of numbers:", linesum)
print("avarage:", avg)
print("variant:", var)

>Solution :

I found your problem. in your sum statement you are trying to compare the string value of y (which is what readlines gives) when it should be a float value.

Try this:

#how to calculate variant of numbers
    var = sum((float(y)-avg) **2 for y in linelist) / countline
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading