Day 204簡単なカウントダウンタイマー

2026-09-16 JST ・ 難易度: 入門 ・ カテゴリ: 標準ライブラリ

Pythonコード

1import time2 3def countdown(t):4    while t:5        mins, secs = divmod(t, 60)6        timer = '{:02d}:{:02d}'.format(mins, secs)7        print(timer, end="\r")8        time.sleep(1)9        t -= 110    print('タイマー終了!')11 12t = input('カウントダウン時間を入力してください(秒): ')13try:14    t = int(t)15except ValueError:16    print('数値を入力してください。')17else:18    countdown(t)

解説

次に試してみよう