I'm starting my first project in Python(started two weeks ago).
This is something that I didn't learn on the course and it's not very clear on internet due to many different ways to do it. This is the bit of code I have written and I need the input to be saved in a text file, to have the list of names of the employees.
if name.lower() == "add":
n_input = input("Name:")
with open('names.txt', 'w') as f:
f.write(n_input)
When I run this it works perfect, no traceback. But it's not saving the input in the list. I accept critiques, recommendations, changes, etc. As I said I'm new and I only want to learn.
Thank you very much.
FULL CODE BELOW:
snames = list()
f_n = (open('names.txt')).read()
#names_f = f_n.read()
print("Welcome to NAME.app")
while True:
name = input("Please select waiter/tress name - ADD to save new name - LIST to see saved names:")
#try:
if name.lower() == "add":
n_input = input("Name:")
with open('names.txt', 'w') as f:
f.write(n_input)
continue
elif name == snames:
print(name)#doubtful line. print name of list.
elif name.lower() == "list":
print(f_n)
elif name == "exit":
exit()