I have tried some codes myself based off of codes I found online but none seems to be working.
The text file contains something as such:
Student ID: 1230345
Course code:FHCT1024
Grade: A
GPA: 4.0000
CGPA :4.0000
and I want to delete the line with the string 'CGPA'
in it. I tried using:
with open("file.txt", 'r') as inp, open("file.txt", 'w') as f:
for line in inp:
if line.strip().startswith("CGPA"):
pass
else:
f.write(line)
But this deleted everything.