This code is supposed to be the "user" system for my app. This will ask you what you want to do...
If you want to add a user, remove a user or check the list of saved users. With this I learned how to open and edit text files. And my goal doing projects is keep on learning and maybe someday I will be able to work or professionally use Python.
This code is working at the moment, but I wanted to know if is too basic or too complicated with some more professional eyes on it (please consider my 3 weeks knowledge).
snames = list()
f_n = (open('names.txt')).read()
print("Welcome to NAME.app")
################## USER LOGG IN #######################
while True:
name = input("\n - Insert name to logg in \n - ADD to save new user \n - LIST to see saved users \n - REMOVE to delete a user \n - EXIT to finish \n ...")
if name.lower() == "add":
n_input = input("Name:")
with open('names.txt', 'a') as f:
f.write(n_input + '\n')
f.close()
continue
elif name.lower() == "list":
with open('names.txt') as f:
print(f.read().splitlines())
elif name in f_n:
print("Logged as", name.upper())
nxt = input('Welcome, press enter to continue \n')
if nxt == '':
break
elif name.lower() == 'remove':
rem = input("Insert user name to remove \n ...")
with open('names.txt', 'r+') as f:
l=f.readlines()
l=[z for z in l if rem not in z]
with open('names.txt', 'w') as f:
f.writelines(l)
elif name.lower() == "exit":
exit()
name = name.lower()
\$\endgroup\$.lower()
in each place orname = name.lower()
. For me was much better to put it on every single place to I would know what's doing (better readability) But maybe I'm wrong and people prefer as you put it!! Let me know. \$\endgroup\$