鬧鐘

import sys import time import subprocess # 與系統交互的模塊 import random set_time = input('設置鬧鐘時間(舉例8;00):') print(f'鬧鐘設置爲:{set_time}') #記錄時間 print('現在的時間是:') # run = True # while run: # t = time.localtime() # fmt = "%H:%M:%S" # now = time.strftime(fmt, t) # 將localtime轉換爲字符串格式的樣式,易於人類識別 # # print(now) # # print(now + '\r', end = '', flush = True) # flush 刷新 \r # # print(now , end = '', flush = True) # sys.stdout.write(now + '\r') # 與上面效果相同 # sys.stdout.flush() # time.sleep(1) # if now[:5] == set_time.rjust(5, '0'): # print('time up') # subprocess.Popen(['start', '後會無期.mp3'], shell =True) # run = False # break def alert(): ''' 鬧鐘本身 ''' run = True while run: t = time.localtime() fmt = "%H:%M:%S" now = time.strftime(fmt, t) # 將localtime轉換爲字符串格式的樣式,易於人類識別 # print(now) # print(now + '\r', end = '', flush = True) # flush 刷新 \r # print(now , end = '', flush = True) sys.stdout.write(now + '\r') # 與上面效果相同 sys.stdout.flush() time.sleep(1) if now[:5] == set_time.rjust(5, '0'): print('time up') subprocess.Popen(['start', '後會無期.mp3'], shell =True) # run = False run = not random_math() def random_math(): '''隨機數學題''' # while True: a = random.randint(1, 10) b = random.randint(1,10) print(f'please answer:a + b = {a} + {b}=') answer = int(input('輸入結果')) if answer == a + b: print('ok') return True # break #不然會一直循環 else: print('no') return False # return True def main(): alert() # random_math() if __name__ == '__main__': main()
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章