You can do it in the following:
# If there is only one number written in text.txt,
with open('text.txt', 'r') as txt:
N1 = txt.read() # N1 = '1'
N2 = int(N1) + 11 # N2 = 12
with open('text.txt', 'w') as txt:
When you open txt.write(str(N2) #text.txt, the number 12 is entered
© 2024 OneMinuteCode. All rights reserved.