파이썬 연습 문제 정답 — D세트
문제 1. 점수 메시지
score = int(input("점수 입력: "))
if score == 100:
print("만점!")
elif score >= 90:
print("훌륭해요")
elif score >= 70:
print("잘했어요")
else:
print("다음엔 더 잘해봐요")
문제 2. 제품 등급 (중첩 if)
score = int(input("점수 입력: "))
if score >= 90:
print("최우수")
print("판매가능")
elif score >= 80:
print("우수")
print("판매가능")
elif score >= 70:
print("보통")
else:
print("불량")
문제 3. 역순 출력 (while)
n = int(input("N 입력: "))
while n >= 1:
print(n)
n -= 1
문제 4. break와 continue
n = 0
while n < 15:
n += 1
if n % 5 == 0:
continue
print(n)
if n == 12:
break
문제 5. 3의 배수 출력 (for)
n = int(input("N 입력: "))
for i in range(1, n + 1):
if i % 3 == 0:
print(i)
문제 6. 리스트 평균 (for)
scores = [88, 74, 92, 65, 81]
total = 0
for s in scores:
total += s
print("평균:", total / len(scores))
문제 7. 합·차·곱 출력 함수
def show_calc(a, b):
print("합:", a + b)
print("차:", a - b)
print("곱:", a * b)
a = int(input("첫 번째 수: "))
b = int(input("두 번째 수: "))
show_calc(a, b)
문제 8. 인사 반복 함수
def greet(name, n):
for i in range(n):
print("안녕, {}!".format(name))
name = input("이름: ")
n = int(input("횟수: "))
greet(name, n)