Python doesn't save a text file after closing the program

Solution 1:

Use the full path to the file instead of just the name of the file and it should work fine For example:

with open(r'E:\Project\level'+str(n+3)+'.txt', 'w+') as f: