상세 컨텐츠

본문 제목

Loop

Python

by techbard 2024. 11. 18. 14:28

본문

반응형

 

# while loop
#
# Write a while loop that is initialized at 0 and stops at 15.
# If the counter is an even number, append the counter to 
# a list called eve_nums.

eve_nums = []
start = 0
stop = 15

while start <= stop:
    if start % 2 == 0:
        eve_nums.append(start)
    start += 1

print(eve_nums) # 0도 짝수임

# 결과
[0, 2, 4, 6, 8, 10, 12, 14]
반응형

관련글 더보기

댓글 영역