1546번 - 평균
N=int(input())
score=list(map(int,input().split()))
s_max=max(score)
for i in range(N):
score[i]=(score[i]/s_max*100.0)
print(sum(score)/N)
이렇게 쓰면 옳은 답이 나오는데
N=int(input())score=list(map(int,input().split()))for i in range(N): score[i]=score[i]/max(score)*100.0print(sum(score)/N)
이렇게 쓰면 답이 안나옵니다...!
차이는 위에 max를 따로 선언해준거 밖에 없는데 무엇이 문제일까요?
후자는 루프를 도는 중간에 score 배열이 변하면서 max(score)도 중도에 100으로 변하게 됩니다.
댓글을 작성하려면 로그인해야 합니다.
ekrud 3년 전
N=int(input())
score=list(map(int,input().split()))
s_max=max(score)
for i in range(N):
score[i]=(score[i]/s_max*100.0)
print(sum(score)/N)
이렇게 쓰면 옳은 답이 나오는데
N=int(input())
score=list(map(int,input().split()))
for i in range(N):
score[i]=score[i]/max(score)*100.0
print(sum(score)/N)
이렇게 쓰면 답이 안나옵니다...!
차이는 위에 max를 따로 선언해준거 밖에 없는데 무엇이 문제일까요?