I am currently making a script for school work that will have many functions but the one I am stuck on is the remove function. Basically, what it needs to do is remove a line that the user desires from the 10 lines that there are (We can only allow 10 lines written. so for example, if the document has:
1
2
3
4
5
6
7
8
9
10
and I try and remove 8, it would rewrite like this:
1
2
3
4
5
6
7
9
10
My current code is here.
elif action1 == '2':
linetoremove = input('What line would you like to remove? (1 up to 10)')
with open('highscore.txt', 'r') as fin:
data = fin.read().splitlines(True)
with open('highscore.txt', 'w') as fout:
fout.writelines(data[int(linetoremove)]:)
Removes line 1 fine, but any number above will remove all numbers below. I know that such removing should happen, but I cannot find a way of doing it so only 1 line is removed.
Thanks Conn