본문 바로가기
개발일지/Python

파이썬 남은 목표학점 구하기 및 튜플 조작

by 개발에정착하고싶다 2022. 5. 12.
320x100

3학년까지 받은 학점을 scores 변수에 저장해주고.

남은 1학년 동안에 받아야할 각 학기별 학점을 구해주고

그 목표를 추가하여 scores를 4학년 졸업까지 가정하여 만들어보자.

target_point = round((4.0 * 8),2)

scores = (3.7,4.2),(2.9,4.3),(4.1,4.2)

until_3grade_total_point =0

for a in scores:
    for b in a:
        until_3grade_total_point += b

until_3grade_total_point = round(until_3grade_total_point,2)

# 이제 4학년의 것을 구하기.

new_target = target_point - until_3grade_total_point
per_half_grade = round((new_target / 2),2)

scores = list(scores)
scores.append((per_half_grade,per_half_grade))
scores = tuple(scores)
print(scores)

300x250