알고리즘/Baekjoon

[백준][python] 1546번: 평균

팽팽 2022. 2. 3. 21:28

https://www.acmicpc.net/problem/1546

 

1546번: 평균

첫째 줄에 시험 본 과목의 개수 N이 주어진다. 이 값은 1000보다 작거나 같다. 둘째 줄에 세준이의 현재 성적이 주어진다. 이 값은 100보다 작거나 같은 음이 아닌 정수이고, 적어도 하나의 값은 0보

www.acmicpc.net

내 코드

n = int(input())
lst = list(map(int,input().split()))
new_lst=[]

for i in lst:
    new_lst.append(i/(max(lst) *100))

total = sum(new_lst) / n
print(total)

해결

 

사실... 왜 틀린지 아직도 모르겠다... 다른것이라곤 max()함수를 따로 빼서 쓴거?

append()안에서 max함수를 중첩해서 쓰는건가..?

일단은 해결코드에서 변수를 따로 지정해서 쓰면서 깔끔해짐.

n = int(input())  # 과목 수
test_list = list(map(int, input().split()))
max_score = max(test_list)

new_list = []
for score in test_list :
    new_list.append(score/max_score *100)  # 새로운 점수 생성
test_avg = sum(new_list)/n
print(test_avg)