I am trying to get this to run on each line of a .txt file.
D1 =int(lines[0])*10
D2 =int(lines[1])*9
D3 =int(lines[2])*8
D4 =int(lines[3])*7
D5 =int(lines[4])*6
D6 =int(lines[5])*5
D7 =int(lines[6])*4
D8 =int(lines[7])*3
D9 =int(lines[8])*2
D10=int(line[9])*1
Sum =(D1+D2+D3+D4+D5+D6+D7+D8+D9)
Mod = Sum % 11D11= 11 - Mod
if D11 == 10:D11 = 'X'
Basically, the text file contains ISBN-10 numbers that I need to verify by running this code on each of the numbers inside of the text file. Here is where lines is defined because the text file contains "-" and I need to remove those before i start the process shown above.
filename = input("Enter the name of the .txt file: ")
file = open(filename, "r")
lines = file.read()
if "-" in lines:lines = lines.replace("-", "")
lines = file.readline()
while lines:D1 =int(lines[0])*10D2 =int(lines[1])*9D3 =int(lines[2])*8D4 =int(lines[3])*7D5 =int(lines[4])*6D6 =int(lines[5])*5D7 =int(lines[6])*4D8 =int(lines[7])*3D9 =int(lines[8])*2D10=int(lines[9])*1Sum =(D1+D2+D3+D4+D5+D6+D7+D8+D9)Mod = Sum % 11D11= 11 - Modif D11 == 10:D11 = 'X'if D10 == D11:print("Your ISBN-10's are Valid!")else:print("Your ISBN-10's are invalid")