Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save jennyonjourney/bec7ce2773bae16b95d7c1a537859510 to your computer and use it in GitHub Desktop.
Save jennyonjourney/bec7ce2773bae16b95d7c1a537859510 to your computer and use it in GitHub Desktop.
Python - while함수
hap=0
i = 0 #초기값
while i <= 10:
print("아기 상어", i)
hap+=i #hap에 계속 누적을 하는 것이다.
i+=1 #증감
print(hap)
#0~200까지 3의 배수들의 합
hap=0
i=0
while i<200:
hap+=i
print(i,hap)
i+=3
print(hap)
#조건문을 활용할 수도 있다. 언제 더해지는지가 보인다.
hap=0
i=0
while i<200:
if not i%3: #왜 여기서 끝났는지 궁금해요!
hap+=i
print(i,hap)
i+=1
print(hap)
#조건문을 활용할 수도 있다. 언제 더해지는지가 보인다.
hap=0
i=0
while i<200:
if i%3==0: #왜 여기서 끝났는지 궁금해요!
hap+=i
print(i,hap)
i+=1
print(hap)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment