so as i have written in title i have problem with 2 things, mainly i want to add values in to a list and dont delete already existing, but i cant figure out how to do it, for now when im writing something everything old gets deleted. My second problem is that i cant make condition to use upper letter T and lower t, can anyone help me? here is the code:
import pickle
zadania = []
a = input("Do you want to add value? T/N")
while True:
if a == 'T':
zadania.append(str(input('Write what you want to add: ')))
a = input("Do you want add something else? T/N")
elif a == 'N':
break
else:
while a not in 'TN':
print("Wrong value")
a = input("Do you want add something else? T/N")
with open('zad', 'wb') as fp:
pickle.dump(zadania, fp)
>Solution :
zadania = []
This always starts with an empty list. If you don’t want that, then you should do something different. For example, you could check if the file you wrote before already exists. If it does, load it before getting more items.