Код детали показан ниже:
Код: Выделить всё
def check_order(self):
check = input("Is the order correct?: (*yes/no)")
if check == 'yes' or check == "Yes":
def print_receipt(self):
index =[]
table = []
headers = ['No','Item Name', 'Item Qty', 'Item Price', 'Total Price']
for idx, _ in enumerate(self.item_dict, start=1):
index.append(idx)
for key, value in self.item_dict.items():
table.append([key, value[0], value[1], value[0]*value[1]])
print(tabulate(table, headers=headers, tablefmt='fancy_grid', stralign="center", showindex=index))
elif check == 'no' or check == 'No':
edit = input("Specify the column you want to input: (*name/quantity/price)")
if edit == 'name' or edit == 'Name':
old_name = input("Write the wrong item name (*make sure the item name is correct):")
new_name = input("Write the new item name:")
def update_item_name(self, old_name, new_name):
if old_name in self.item_dict.keys():
item_list = self.item_dict.get(old_name)
self.item_dict.pop(old_name)
self.item_dict.update({new_name : item_list})
else:
raise Exception("Item does not exist")
return self.item_dict
Интересно, действительно ли мы не можем вставить функцию в оператор if-else? Что-то не так с моим кодом или есть ли лучшее решение этой проблемы?
Подробнее здесь: https://stackoverflow.com/questions/793 ... d-function
Мобильная версия