程序运行时,它会等待5秒钟以播放音乐,但此后每秒钟播放一次音乐

时间:2020-08-23 09:50:58

标签: python

程序每次播放音乐应等待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")

1 个答案:

答案 0 :(得分:3)

你做到了

u_t=water_t

但是u_t只能在其他地方使用。

应该是

water_t=time()