Python не записывает текст в конец даже при условии открытия 'a'(append)

При f = open('values.txt','a')

Записывает не в новую строку ,а в первую

Пробовал другой способ но потерял его

import os.path
path = 'values.txt'

def repeat():
    
    print('Write:1 Read:2 Exit:3')
    while(True):
        print('Type')
        x = int(input())
        
        wr(x)
        
def wr(x):
    f = open('values.txt','a')
    fr = open('values.txt','r')
    if x == 1:
        print('Enter text')
        a = input()
        f.write(a)
    if x == 2:
        for line in fr:
            print(line)
    if x == 3:
        exit("User Exit")

if os.path.exists(path) == False:
    with open(path, 'w') as f:
        print('file created')
        repeat()
        
else:
   repeat()```

Ответы (1 шт):

Автор решения: OverNiko

То о чём сказано в комментариях

import os.path
path = 'values.txt'

def repeat():
    
    print('Write:1 Read:2 Exit:3')
    while True:
        print('Type')
        x = int(input())
        
        wr(x)
        
def wr(x):
    f = open('values.txt','a')
    fr = open('values.txt','r')
    if x == 1:
        print('Enter text')
        a = input()
        f.write(a)
        f.close() # +++
    if x == 2:
        for line in fr:
            print(line)
        fr.close() # +++
    if x == 3:
        exit("User Exit")

if os.path.exists(path) == False:
    with open(path, 'w') as f:
        print('file created')
        repeat()
        
else:
   repeat()
→ Ссылка