Movatterモバイル変換


[0]ホーム

URL:


はてラボはてな匿名ダイアリー
ようこそ ゲスト さんログインユーザー登録
< anond:20240802203650 |anond:20240802203528 >

2024-08-02

importos

importos

#ファイルパス指定

file_path = 'year_count.txt'

#ファイル存在するか確認し、存在しない場合は初期値を設定

if notos.path.exists(file_path):

withopen(file_path, 'w')as file:

file.write('1') #最初の年数を1に設定

#現在の年数を読み込み

withopen(file_path, 'r')as file:

year_count = int(file.read())

#メッセージを表示

print(f"{year_count}年間で最も暑い夏")

# 年数を+1してファイルに保存

withopen(file_path, 'w')as file:

file.write(str(year_count + 1))

インデントつけれね

Permalink |記事への反応(0) | 20:39

このエントリーをはてなブックマークに追加ツイートシェア

記事への反応 -

記事への反応(ブックマークコメント)

全てのコメントを見る

人気エントリ

注目エントリ

ログインユーザー登録
ようこそ ゲスト さん
Copyright (C) 2001-2025 hatena. All Rights Reserved.

[8]ページ先頭

©2009-2025 Movatter.jp