'''
파이썬 반복문 - for, while
for 변수 in 시퀀스:
반복할 명령
while 조건:
반복할 명령
'''
#for문 - 정해진 횟수(길이)
for i in range(1, 6):
print(i)
#while문 - 조건
i = 1
while i <= 5:
print(i)
i += 1 #i = i + 1
#for - 1 ~ 100 더하기
sum = 0
for a in range(1, 101):
sum = sum + a
print(sum)
#while - 1 ~ 숫자 더해서 합이 100을 넘으면 멈춘다
total = 0
n = 1
while True: # 힌트: 무한 반복을 만드는 키워드
total += n #total = total + n # 힌트: total에 n을 더한다
if total > 100 : # 힌트: total이 100보다 크면
break # 힌트: 반복문을 멈추는 명령어
n += 1 # n = n + 1 # 힌트: n을 1씩 증가
print(total, n)
To embed this project on your website, copy the following code and paste it into your website's HTML: