PROGRESS
26 / 26
E12-3.py 점수대별 인원 분포 세기
10 P
QUESTION 26 #555
점수 리스트에서 90이상/80이상/70이상/60이상/59이하 인원을 각각 셉니다. 빈칸에 들어갈 알맞은 누적식을 채우세요.
main.py
scores = [65, 78, 55, 38, 98, 88, 77, 64, 100, 80,
85, 98, 59, 99, 68, 87, 99, 46, 85, 93,
85, 98, 59, 99, 68, 87, 99, 46, 85, 93,
67, 99, 63, 79, 92, 80, 68, 62, 96, 84]
i = 0
count1 = 0
count2 = 0
count3 = 0
count4 = 0
count5 = 0
while i < len(scores) :
if scores[i] >= 90:
elif scores[i] >= 80:
elif scores[i] >= 70:
count3 += 1
elif scores[i] >= 60:
count4 += 1
else :
count5 += 1
i += 1
print(f"90점 이상: {count1}명")
print(f"80점 이상: {count2}명")
print(f"70점 이상: {count3}명")
print(f"60점 이상: {count4}명")
print(f"59점 이하: {count5}명")
print(f"전체인원: {len(scores)}명")
HINT
elif는 위 조건이 False일 때만 검사되므로 각 구간이 한 번씩만 카운트됩니다.
실행 결과 예시
90점 이상: 10명 80점 이상: 9명 70점 이상: 4명 60점 이상: 11명 59점 이하: 6명 전체인원: 40명
INTERACTIVE SHELL
Shift + Enter 로 즉시 실행