Notice
Recent Posts
Recent Comments
Link
SeouliteLab
[Python/파이썬] 카운트다운 타이머 만들기 본문
import time
def countdown_timer(seconds):
while seconds > 0:
print(f"남은 시간: {seconds}초")
time.sleep(1)
seconds -= 1
print("타이머 종료!")
# 카운트다운할 시간 설정 (초 단위)
countdown_time = 10
# 카운트다운 타이머 실행
print(f"{countdown_time}초 카운트다운을 시작합니다.")
countdown_timer(countdown_time)
설명:
- 이 프로그램은 주어진 시간동안 카운트다운을 진행하는 타이머를 만듭니다.
countdown_timer
함수는 입력된 시간(초) 동안 반복문을 통해 카운트다운을 수행합니다.time.sleep(1)
을 사용하여 1초씩 대기하며,seconds
변수를 1씩 감소시켜 카운트다운을 진행합니다.- 카운트다운이 끝나면 "타이머 종료!" 메시지를 출력합니다.
- 테스트용으로 10초 동안의 카운트다운을 시작하고, 결과를 출력합니다.