강의

멘토링

커뮤니티

Inflearn Community Q&A

sarahong9705206595's profile image
sarahong9705206595

asked

Introduction to Python Algorithm Problem Solving (Coding Test Preparation)

섹션2 코드 구현 능력 기르기 4번

Written on

·

228

0

안녕하세요! 섹션 2 코드 구현 능력 기르기의 대표값 문제(4번) 아래와 같은 방식으로 풀면 오답인가요?

채점기를 돌렸을 때는 모든 부분 오답이라고 뜨는데, visual studio에서는 잘 실행 되더라구요! (해당 예시만 실행했을 때)

어느 부분이 잘못된 것인지 질문합니다. 

 

import sys

#sys.stdin=open("input.txt","rt")

N = int(input())

math=list(map(int, input().split()))

avg=round(sum(math)/N)

res=0

for i in range(N):

    for j in range(i+1, N):

        res=i

    if abs(avg-math[i])>abs(avg-math[j]):

            res=j

print(avg, res-1)

python코테 준비 같이 해요!

Answer 1

0

codingcamp님의 프로필 이미지
codingcamp
Instructor

안녕하세요^^

채점폴더에 각 데이터파일이 있으니 그 파일로 스스로 디버그해보세요.

 

sarahong9705206595's profile image
sarahong9705206595

asked

Ask a question