class Journal: def __init__(self): = None self.amount = None self.items = [] def select_date(self, date): = date def enter_amount(self, amount): self.amount = amount def select_item_type(self, item_type): self.items.append(item_type) def remove_item(self, item_type): self.items.remove(item_type) def display_items(self): if self.items: print("Date:", print("Amount:", self.amount) print("Items:") for item_type in self.items: print(f"{item_type}:", end="") for item in self[item_type]: print(f"{item}") print() def load_items(self, items_file): with open(items_file, "r") as f: for line in f: date, amount, item_type = line.strip().split(" ") self.enter_amount(amount) self.select_item_type(item_type) self.display_items() def save_items(self, items_file): with open(items_file, "w") as f: for item_type in self.items: f.write(f"{item_type}: ") for item in self[item_type]: f.write(f"{item}") f.write("\n") if __name__ == "__main__": journal = Journal() journal.load_items("items.txt") journal.select_date("%Y-%m-%d")) journal.enter_amount(100) journal.select_item_type("正餐") journal.remove_item("零食") journal.display_items()