%run error
Title
Question
i am using windows 10,
i place the command, %run desktop/marks.pygot an error....
In [31]: %run desktop/marks.py
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\desktop\marks.py in <module>
8 if region_code=="A":
9 math_marks_A.append(math_mark)
---> 10 math_marks_mean = sum(math_marks_A)/len
11 (math_marks_A)
12 print (math_marks_mean)
TypeError: unsupported operand type(s) for /: 'float' and 'builtin_function_or_method'
<font color="#330099">the code as below:</font>
<font color="#330099">math_marks_A=[]</font>
<font color="#330099">for line in open("desktop/student_record.txt"):</font>
<font color="#330099"> fields=line.split(";")</font>
<font color="#330099"> region_code=fields[0]</font>
<font color="#330099"> region_code_stripped=region_code.strip()</font>
<font color="#330099"> math_mark_str=fields[5]</font>
<font color="#330099"> math_mark=float(math_mark_str)</font>
<font color="#330099"> if region_code=="A":</font>
<font color="#330099"> math_marks_A.append(math_mark)</font>
<font color="#330099">
</font>
</font>
<font color="#330099">
</font>
</font>
<font color="#330099">math_marks_mean = sum(math_marks_A)/len</font>
<font color="#330099">(math_marks_A)</font>
<font color="#330099">print (math_marks_mean)</font>
<font color="#330099">
</font>
</font>
Python-3.4.3 Parsing-data 10-11 min 20-30 sec
Answers:
You have error in math_marks_mean = sum(math_marks_A)/len.
It should be math_marks_mean = sum(math_marks_A)/len(math_marks_A)
Login to add comment