Добавил:
Katynska
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз:
Предмет:
Файл:
from datetime import datetime
#выводит общий список товаров с ценами
def allInvent():
for key in inventInstore:
print(key , inventInstore[key])
#удаляет товар
def deleteValue(dict):
key = input("Введите ключ для удаления из словаря\n: ")
if key in dict:
del dict[key]
else:
print("Товар не найден")
#обновляет товар
def updateValue(dict):
key = input("Введите ключ для обновления\n: ")
value = input("Введите новое значение\n: ")
dict[key] = value
return dict
inventInstore = {'potato': 45, 'cabbage': 50, 'carrot': 30, 'tomato': 25}
num = input("Выберите команду (1-вывести словарь, 2-добавить в словарь, 3-удалить из словаря)\n: ")
if num == "1":
print("\nВывод всех товаров\n")
allInvent()
log_file = open("log_file.txt", "a")
current_datetime = datetime.now()
log_file.write("\nоперация: \"Вывод всех товаров\" "+str(current_datetime))
log_file.close()
elif num == "2":
print("\nОбновление\n")
allInvent()
updateValue(inventInstore)
allInvent()
log_file = open("log_file.txt", "a")
current_datetime = datetime.now()
log_file.write("\nоперация: \"Обновление\" "+str(current_datetime))
log_file.close()
elif num == "3":
print("Удаление ")
allInvent()
deleteValue(inventInstore)
allInvent()
log_file = open("log_file.txt", "a")
current_datetime = datetime.now()
log_file.write("\nоперация: \"Удаление\" "+str(current_datetime))
log_file.close()
else:
print("Неизвестная команда")
log_file = open("log_file.txt", "a")
current_datetime = datetime.now()
log_file.write("\nоперация: \"Неизвестная команда\" "+str(current_datetime))
log_file.close()