본문 바로가기
Algorithm

[구현/수학] 백준 25206 너의 평점은 - 파이썬(Python)

by jangThang 2022. 11. 24.
반응형

백준 온라인 저지

 

[ Contents ]

     

     

    1. 문제 (링크 참조)

     

    25206번: 너의 평점은

    인하대학교 컴퓨터공학과를 졸업하기 위해서는, 전공평점이 3.3 이상이거나 졸업고사를 통과해야 한다. 그런데 아뿔싸, 치훈이는 깜빡하고 졸업고사를 응시하지 않았다는 사실을 깨달았다! 치

    www.acmicpc.net

     

     

     

    2. 문제 풀이

     한줄씩 과목명과 학점, 평점이 주어집니다. 이를 추합해서 전체 평점 평균을 구해야 합니다. (단, Pass 과목은 제외)

     

     

     

    3. 코드

    import sys
    input = sys.stdin.readline
    
    score = 0
    num = 0
    for _ in range(20):
        _, credit, grade = input().rstrip().split()
    
        if grade == 'A+':
            score += float(credit)*4.5
        elif grade == 'A0':
            score += float(credit)*4
        elif grade == 'B+':
            score += float(credit)*3.5
        elif grade == 'B0':
            score += float(credit)*3.0
        elif grade == 'C+':
            score += float(credit)*2.5
        elif grade == 'C0':
            score += float(credit)*2.0
        elif grade == 'D+':
            score += float(credit)*1.5
        elif grade == 'D0':
            score += float(credit)*1.0
        elif grade == 'F':
            pass
    
        if grade == 'P':
            pass
        else:
            num += float(credit)
    print(score/num)

     파이썬은 switch문이 없으므로 if - elif문으로 일일이 분기를 나눠야 합니다. Pass는 평점에서 제외하는 걸 유의하며, 평점별로 점수를 계산합니다.

     

    star가 되고나서 Tistory

    반응형

    댓글