from pathlib import Path

def leer_numeros(nombre_archivo):
    ruta = Path(nombre_archivo)
    print(ruta)
    if not ruta.exists():
        print(f"El archivo {nombre_archivo} NO existe.")
        return []

    numeros = []
    with open(nombre_archivo, "r") as archivo:
        for linea in archivo:
            try:
                numeros.append(float(linea.strip()))
            except ValueError:
                pass
    return numeros

def agregar_un_numero(nombre_archivo, numero):
    with open(nombre_archivo, "a") as archivo:
        archivo.write(f"{numero}\n")

def sobrescribir_numeros(nombre_archivo, lista_numeros):
    with open(nombre_archivo, "w") as archivo:
        for num in lista_numeros:
            archivo.write(f"{num}\n")

agregar_un_numero("datos.txt", 1.14)
agregar_un_numero("datos.txt", 2.71)
agregar_un_numero("datos.txt", 3.71)
agregar_un_numero("datos.txt", 4.71)
agregar_un_numero("datos.txt", 5.71)

#sobrescribir_numeros("datos.txt", [1.0, 2.0, 3.0, 4.0, 5.0])
print(leer_numeros("datos.txt"))