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してファイルに保存
file.write(str(year_count + 1))
インデントつけれね
Permalink |記事への反応(0) | 20:39
ツイートシェア