You are checking if the line is 1801. You should check if 1801 is in the line.
You should use if '1801' in line:
Since you need to check for any number between 1801 and 2000, you need to use a range. The numbers are going to be integers in the range. So convert them to string before you check.
EDIT Ver 2: Read & Write to file:
with open("abc.txt", "r") as f_in, open("out.txt", "w") as f_out:
for line in f_in:
if not any(str(i) in line.strip() for i in range(1801, 2001)):
f_out.write(line)
Input file:
2 1801 0.417 # do not write to output file
2 1802 0.795 # do not write to output file
2 1750 0.234 # write to output file
2 1803 0.129 # do not write to output file
2 1779 0.123 # write to output file
2 1804 0.852 # do not write to output file
2 1760 0.345 # write to output file
Output File:
2 1750 0.234 # write to output file
2 1779 0.123 # write to output file
2 1760 0.345 # write to output file
EDIT Ver 1: Concept logic
Try this. Instead of a file, I am just putting the whole data into a string and processing. Let me know if you want a full file read and write implementation.
sample_data = '''2 1801 0.417
2 1802 0.795
2 1750 0.234
2 1803 0.129
2 1779 0.123
2 1804 0.852
2 1750 0.345'''
for line in sample_data.split('\n'):
if not any(str(i) in line for i in range(1801, 2001)):
print ('written to file - line :',line)
else:
print ('skipped line ',line)
The output of this will be:
skipped line 2 1801 0.417
skipped line 2 1802 0.795
written to file - line : 2 1750 0.234
skipped line 2 1803 0.129
written to file - line : 2 1779 0.123
skipped line 2 1804 0.852
written to file - line : 2 1750 0.345