程序每次播放音乐应等待5秒钟。 代码-
from pygame import mixer
from time import time
from datetime import datetime
def music(file,stopper):
mixer.init()
mixer.music.load(file)
mixer.music.play()
while True:
var=input()
if var==stopper:
mixer.music.stop()
break
def logs(msg):
with open("logs.txt","a") as f:
f.write(f"{datetime.now()} {msg}\n")
if __name__ == "__main__":
water_t=time()
eyes_t=time()
exercise_t=time()
water_s=5
while True:
if time()-water_t>water_s:
print(time()-water_t)
print("Enter done to stop the alarm")
music('water.mp3',"done")
u_t=water_t
logs("Water drank at")
答案 0 :(得分:3)
你做到了
u_t=water_t
但是u_t
只能在其他地方使用。
应该是
water_t=time()