Algorithm(알고리즘)/백준
05_백준 4344 파이썬 -평균은 넘겠지
고로케
2021. 6. 17. 00:41
반응형
출력값이 xx.000 형식으로 고정돼있다.
f string 방식에서 소수점 출력에 조건을 주어야 한다. 소수점 출력 방식 {x:.3f} 를 f string 방식으로 아래와 같이 써줄 수 있다. print(f'{x:.3f}%')
- 풀이
n = int(input())
def avg(students):
total_students = students[0]
avg_point = sum(students[1:]) / total_students
top_students = 0
for i in students[1:]:
if i > avg_point:
top_students +=1
top_rate = top_students/total_students *100
return top_rate
for i in range(n):
students = list(map(int, input().split()))
x = round(avg(students),3)
print(f'{x:.3f}%')
반응형