고통은 사라지고 결과는 남는다. Records of Chansolve

Python으로 스톱워치를 만들어보자 본문

IT

Python으로 스톱워치를 만들어보자

엄청큰노란닭 2023. 4. 6. 11:01

일 하다가 집중하는 시간을 늘리려고 스톱워치를 만들었습니다.

import time

start_time = time.localtime()
print(f"시작시간: {start_time.tm_hour}:{start_time.tm_min:02d}:{start_time.tm_sec:02d}")

count = 0

while True:
    minute = count // 60
    second = count % 60
    hour = minute // 60
    minute %= 60
    if hour < 10:
        print(f"0{hour}:{minute:02d}:{second:02d}")
    else:
        print(f"{hour}:{minute:02d}:{second:02d}")
    time.sleep(10)
    count += 10

    if count % (60 * 60) == 0:
        print(f"{hour + 1}시간이 경과했습니다. 휴식을 권장드립니다.")

    if count % (60 * 60 * 5) == 0:
        print(f"{hour}시간이 경과했습니다. 반드시 휴식을 취하시길 바랍니다.")

    if hour == 99 and minute == 59 and second == 59:
        print("최대 시간이 되어 프로그램을 종료합니다.")
        end_time = time.localtime()
        print(f"종료 시간: {end_time.tm_hour}:{end_time.tm_min:02d}:{end_time.tm_sec:02d}")
        break

'IT' 카테고리의 다른 글

mysqlclient Error  (0) 2023.12.04
Django for문 여러 개 쓰는 방법  (0) 2023.10.05
Python: TCP/IP 소켓 통신  (0) 2023.09.13
챗GPT(chatGPT)란  (0) 2023.02.21
Anaconda 가상환경  (0) 2023.02.16
Comments