python/반복문
반복문 기본문제[2단계]
june__Park
2021. 2. 16. 22:26
# 반복문 기본문제[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)