Reputation:
I have attached an excel sheet and with the help of python code below I'm trying to fetch those roll numbers who have either secured marks less than 40 or are having an attendance below 75 percent.
But every time I run the code I face an error message :
Traceback (most recent call last): 87.0 File "C:/Users/Shubham Mishra/PycharmProjects/Python/jacc.py", line 11, in value1 = (int)(worksheet.cell(i, 2).value) ValueError: invalid literal for int() with base 10: 'Attendance'
import xlrd
workbook=xlrd.open_workbook('log.xls')
worksheet=workbook.sheet_by_index(0)
print(worksheet.cell(1,2).value)
i=1
n=6
for i in range(n):
value1 = (int)(worksheet.cell(i, 2).value)
value2 = (worksheet.cell(i, 3).value)
if ((value1<=75) or (value2<=40)):
print(worksheet.cell(i,1))
Upvotes: 0
Views: 105
Reputation: 5570
The main problem in your code is that range
function starts with 0.
So the first loop's iteration is:
value1 = (int)(worksheet.cell(0, 2).value)
that corresponds to "Attendance" string.
This is the reason because you have this error.
You should think to change your code in something like this:
n=7
for i in range(1, n):
value1 = (int)(worksheet.cell(i, 2).value)
value2 = (worksheet.cell(i, 3).value)
if ((value1<=75) or (value2<=40)):
print(worksheet.cell(i,1))
please note that n
is equals to 7 and not 6 anymore.
Upvotes: 1