Created
March 25, 2018 01:43
-
-
Save jennyonjourney/bec7ce2773bae16b95d7c1a537859510 to your computer and use it in GitHub Desktop.
Python - while함수
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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