def add_record(): d = input("日付(空欄で今日): ") or str(date.today()) category = input("項目: ") amount = int(input("金額(支出はマイナスで記入): ")) note = input("メモ: ")
with open(FILENAME, "a", newline="", encoding="utf-8") as f: writer = csv.writer(f) writer.writerow([d, category, amount, note]) print("記録しました。")
def show_records(): total = 0 print("\n=== 家計簿一覧 ===")
try: with open(FILENAME, "r", encoding="utf-8") as f: reader = csv.reader(f) for row in reader: print(row) total += int(row[2]) print(f"\n合計残高: {total}円\n") except FileNotFoundError: print("記録がありません。\n")
コメント