반응형

파이썬, 크리스마스 X-MAS 예제 코드

 

터미널에서 실행합니다.

 

python x-mas.py

 

 

[ x-mas.py ]

import time

 

msg = "메리 크리스마스\n"

 

def christmas_tree(height):

for i in range(height):

print(" " * (height - i - 1) + "*" * (2 * i + 1))

if height > 4:

print(" " * (height - 1) + "||")

else:

print(" " * (height - 1) + "|")

 

def display_merry_christmas(i):

print(msg[:i])

 

def xmas_animation():

frames = 5 # 변경할 프레임 수

 

while True:

for _ in range(frames):

print("\033c") # 터미널 화면 클리어

 

for i in range(2, 10, 2):

christmas_tree(i)

display_merry_christmas(i)

time.sleep(0.5)

print("\033c") # 터미널 화면 클리어

 

xmas_animation()

 

[ 실행 화면 ] 애니메이션...

 
반응형

+ Recent posts