본문 바로가기

Programming [Python]/백준 알고리즘 솔루션

#307 백준 파이썬 [10984] 내 학점을 구해줘

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

 

PYTHON CODE

T = int(input())

for _ in range(T):
    N = int(input())
    total_credit = 0
    total_grade = 0
    
    for _ in range(N):
        credit, grade = map(float, input().split())
        total_credit += credit
        total_grade += credit * grade
        
    GPA = total_grade / total_credit
    print(int(total_credit), '%.1f' % GPA)