[BOJ / Python] 4344 평균은 넘겠지

도니·2023년 4월 6일

BOJ / Python

목록 보기
39/105
post-thumbnail

문제

백준 4344 평균은 넘겠지

코드

#BOJ 4344 평균은 넘겠지

c = int(input())

for _ in range(c):
    scores = list(map(int, input().split()))
    avg = sum(scores[1:]) / scores[0]
    count = 0
    for x in scores[1:]:
        if x > avg:
            count += 1
    print(f'{count/scores[0]*100:.3f}')

파이썬 소수점 자릿수 제한 방법

  1. f-string
    f'문자열 {변수:.3f} 입니다'
    ➡️ f'{count/scores[0]*100:.3f}
  2. format 형식 지정
    "문자열 {:.3f} 문자열 {:.3f}".format(값1, 값2)
    ➡️ print("{:.3f}".format(count/scores[0]*100))
  3. rount 함수 사용
    round(반올림하고자 하는 값, 자릿수)
    ➡️ print(round(count/scores[0]*100, 3))
profile
Where there's a will, there's a way

0개의 댓글