I have entered the following code in the editormath_marks_A = []for line in open("student_record.txt"): fields = line.split(";") region_code = fields[0] region_code_stripped = region_code.strip() math_mark_str = fields[5] math_mark = float(math_mark_str) if region_code == "A": math_marks_A.append(math_mark)but i am getting the following error after running the fileTraceback (most recent call last): File "/home/ranjeet/Desktop/python_plot/marks.py", line 6, in <module> math_mark_str = fields[5]IndexError: list index out of rangeplease help
When should we use %run -i<file name> command and when should we use %run <file name> command?
In [27]: %run marks.py File "C:\Users\wci\marks.py", line 8 if region_code== "A"; ^SyntaxError: invalid syntax
after typing the last command %run marks.py , it shows an error as%run marks.py---------------------------------------------------------------------------NameError Traceback (most recent call last)~\marks.py in <module> 9 math_marks_A.append(math_mark) 10---> 11 math_marks_mean=sum(math_maths_A)/len(math_marks_A) 12 print(math_marks_mean)NameError: name 'math_maths_A' is not defined
In [29]: %run marks.pyIn [30]: %run marks.py---------------------------------------------------------------------------TypeError Traceback (most recent call last)~\marks.py in <module> 10 11---> 12 math_marks_mean = sum(math_marks_A) / len 13 (math_marks_A) 14 print (math_marks_mean)TypeError: unsupported operand type(s) for /: 'float' and 'builtin_function_or_method'
%run marks.pyit shows that math_marks_mean = sum(math_marks_A)/len(math_marks_A)then it shows that type error : unsupported operand type(s) for /: 'float' and 'builtin_function_or_method,
I tried running the command after saving the marks.py in the working directory but it still shows%run mark.py File "C:\Users\HP\mark.py", line 2 for line in open("student_record.txt") ^SyntaxError: invalid syntax
can we merge/concatenate/combine two String?
Am not getting the mean value as per video. Its showing an error as %run -i "C:\Users\HP\Desktop\marks.py"ERROR:root:File `'C:\\Users\\HP\\Desktop\\marks.py'` not found.Can you please help me...
After typing the code and using the run command, I am not able to get the mean value.
i am using windows 10,i place the command, %run desktop/marks.py got 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'the code as below:math_marks_A=[]for line in open("desktop/student_record.txt"): fields=line.split(";") region_code=fields[0] region_code_stripped=region_code.strip() math_mark_str=fields[5] math_mark=float(math_mark_str) if region_code=="A": math_marks_A.append(math_mark)math_marks_mean = sum(math_marks_A)/len(math_marks_A)print (math_marks_mean)
1. Shouldn't the answer be line.split(';')?; instead of ,
running file marks.py gives error on line 'math_marks_mean=sum(math_mark)/len'--> 'float' object is not iterable.code written in marks.py file is==>math_marks_A=[]for line in open("student_record.txt"): fields = line.split(";") region_code=fields[0] region_code_stripped=region_code.strip() math_mark_str=fields[5] math_mark=float(math_mark_str) if region_code=="A": math_marks_A.append(math_mark)math_marks_mean=sum(math_mark)/len(math_marks_A)Print(math_marks_mean)
I have confusion between %run file and %run -i file. In both the cases, i am getting the output but i want to know which one to be used in which instance. what does -i indicates in the later command.
137 visits
Outline:پارسینگ دادهها چیست - تابع اسپلیت و ترکیب آن - توکنایزینگ چیست - چگونه رشته را با فواصل سفید جدا کنیم - تابع اسپلیت با آرگومان - تابع استریپ و مثال - تبدیل کردن رشته به عدد اعشاری و عدد صحیح - مثال برای خواندن یک فایل بزرگ دات تی اکس تی به صورت خط به خط و تجزیه هر رکورد - انجام محاسبات روی فایل دات تی اکس تی - اجرای فایل با استفاده از فرمان %رن -
پارسینگ دادهها چیست - تابع اسپلیت و ترکیب آن - توکنایزینگ چیست - چگونه رشته را با فواصل سفید جدا کنیم - تابع اسپلیت با آرگومان - تابع استریپ و مثال - تبدیل کردن رشته به عدد اعشاری و عدد صحیح - مثال برای خواندن یک فایل بزرگ دات تی اکس تی به صورت خط به خط و تجزیه هر رکورد - انجام محاسبات روی فایل دات تی اکس تی - اجرای فایل با استفاده از فرمان %رن -
Show video info
Pre-requisite