Функция для сохранения заметок в текстовый файл
Нужно создать функцию для сохранения заметок в текстовый файл
#показывает заметки
notes = []
if len(notes) == 0:
print("Нету заметок")
else:
print("\nСписок заметок:")
for note in notes:
print(note)
# добавляет заметки
def addNote():
noteToAdd = input("Введите текст заметки: ")
notes.append(noteToAdd)
print("\nЗаметка добавлена успешно!")
return notes
# удаляет заметки
def deleteNote():
noteToDelete = input("Введите текст заметки для удаления: ")
if noteToDelete in notes:
notes.remove(noteToDelete)
print("\nЗаметка удалена успешно!")
else:
print("\nТакая заметка не найдена!")
# показывает первые заметки
def earliestNotes():
earliestNotes = sorted(notes, key=str or float)
for note in earliestNotes:
print(note)
# показывает поздние заметки
def latestNotes():
latestNotes = sorted(notes, key=str or float, reverse=True)
print("\nПознейшие заметки:")
for note in latestNotes:
print(note)
# показывает заметки от длиных до коротких
def longestNotes():
longestNotes = sorted(notes, key=len, reverse=True)
print("\nДлинейшие заметки:")
for note in longestNotes:
print(note)
# показывает от коротких к длинным
def shortestNotes():
shortestNotes = sorted(notes, key=len)
print("\nСамые короткие:")
for note in shortestNotes:
print(note)
# это цикл для показа вариаций выбора
notes = []
while True:
choice = input("\nЩо ви хочете зробити? \n[1] Відобразити нотатки \n[2] Додати нотатку \n[3] Видалити нотатку \n[4] Найраніші нотатки \n[5] Найпізніші нотатки \n[6] Найдовші нотатки \n[7] Найкоротші нотатки \n[q] Вийти \n ")
if choice == '1':
print('|'.join(notes))
elif choice == '2':
addNote()
elif choice == '3':
deleteNote()
elif choice == '4':
earliestNotes()
elif choice == '5':
latestNotes()
elif choice == '6':
longestNotes()
elif choice == '7':
shortestNotes()
elif choice == 'q':
break
else:
print("Введіть правильний варіант!")