See the following code:
def increment(): x = 0 file = open(f'file{x}.txt', 'a') file.write("something...") file.close() x = x + 1 You might have figured out what, I'm trying to do here. But the problem is, each time I run the program the value of x is set to 0 and every time it's opening the file, file1.txt, I even tried this code:
x = 0 def increment(): file = open(f'file{x}.txt', 'a') file.write("something...") file.close() x = x + 1 Assigning the value outside the function, but still the same problem. I want it to open files like this:
First Run: file1.txt,
Second Run: file2.txt,
Third Run: file3.txt and so on...
But it's always opening the file, file1.txt.