私はPythonプログラミングには新しく、私は最近学んだ概念を適用しようとしています。私は他のコードを読んでいて、例を見つけて、それをちょっと微調整しました。問題は、現在の時刻が起床時刻と等しい場合に、elif
ブロックが決してトリガーされない場合です。私は小さなif-else
ステートメントで、それがうまく動作しますが、while loop
の内部で決して起動しないことをテストしました。python-alarm clock suggestions
お知らせください。
import time
import subprocess
wake_hour = int(raw_input("Wake hour: "))
wake_minute = int(raw_input("Wake minute: "))
wake_time = [wake_hour, wake_minute]
current_hour = int(time.strftime("%H"))
current_minute = int(time.strftime("%M"))
current_time = [current_hour, current_minute]
while True:
if current_time != wake_time:
current_hour = int(time.strftime("%H"))
current_minute = int(time.strftime("%M"))
print current_hour, current_minute
print wake_hour, wake_minute
elif current_time == wake_time:
audio_file = "/Users/dcasteli/Documents/emergency018.mp3"
play = subprocess.call(["afplay", audio_file])
print "Wake up!"
どのようなサンプル入力を使用しましたか?このプログラムは、ユーザが 'current_time'にマッチする入力を提供している場合にのみ動作します。 – jonathanking
目覚まし時計を実装する際には、[sleep](https://docs.python.org/3.5/library/time.html#time.sleep)を解除する必要があります。常に時計を見る必要はありません。 – moooeeeep