then I leave you the simplest way to make the menu using input
in case the data record is for a single user:
lista = []
lista.append(input("Introduce tu código: "))
lista.append(input("Introduce tu nombre: "))
lista.append(input("Introduce tu apellido: "))
lista.append(input("Introduce tu ciudad: "))
file = open("datos.txt", "w")
file.write("Codigo: " + lista[0] + "\n")
file.write("Nombre: " + lista[1] + "\n")
file.write("Apellido: " + lista[2] + "\n")
file.write("Ciudad: " + lista[3] + "\n")
file.close()
In case you want to save several user registers and using lists as you have indicated (it would be more correct and simple with dictionaries) it would be such that:
lista = []
menu = True
i = 1
while(menu == True):
lista.append(input("Introduce tu código: "))
lista.append(input("Introduce tu nombre: "))
lista.append(input("Introduce tu apellido: "))
lista.append(input("Introduce tu ciudad: "))
opt = input("¿Desea continuar? (s/n): ")
if(opt == "n"):
menu = False
file = open("datos.txt", "w")
while(i*4<=len(lista)):
file.write("Codigo: " + lista[1*i-1] + "\n")
file.write("Nombre: " + lista[1*i] + "\n")
file.write("Apellido: " + lista[2*i] + "\n")
file.write("Ciudad: " + lista[3*i] + "\n\n")
i += 1
file.close()
This script would update the file only the first time and would overwrite its contents in case of adding records every time you run the script you would have to open the file using file = open("datos.txt", "a")
using the "Appending mode" to add new lines of text .
I hope to be of help, greetings.