June is Combung
반복문 기본문제[2단계] 본문
# 반복문 기본문제[2단계]
# 문제1) 1~5까지의 합 출력
# 정답 1) 15
total = 0
i = 1
while i <= 5:
total = total + i
i = i + 1
print("total =", total)
# 문제2) 1~10까지 반복해 3미만 7이상만 출력
# 정답2) 1, 2, 7, 8, 9, 10
i = 1
while i <= 10:
if 7 <= i or i < 3:
print(i, end=" ")
i = i + 1
print()
# 문제3) 문제2의 조건에 맞는 수들의 합 출력
# 정답3) 37
total = 0
i = 1
while i <= 10:
if 7 <= i or i < 3:
total = total + i
i = i + 1
print("total =", total)
# 문제4) 문제2의 조건에 맞는 수들의 개수 출력
# 정답4) 6
count = 0
i = 1
while i <= 10:
if 7 <= i or i < 3:
count = count + 1
i = i + 1
print("count =", count)
'python > 반복문' 카테고리의 다른 글
반복문 종료(-100) (0) | 2021.02.16 |
---|---|
영수증 출력[2단계] (0) | 2021.02.16 |
구구단 게임[3단계] (0) | 2021.02.16 |
반복문 기본문제[1단계] (0) | 2021.02.16 |
반복문 while (0) | 2021.02.16 |
Comments