본문 바로가기
프로그램

[파이썬] 이자율에 따른 단리, 복리 계산

by 오디세이99 2022. 9. 29.
728x90
반응형

 

def simple_interest(m, p, r):    # 단리 : 원금, 기간(년), 이자율(년, %)
    r = r / 100
    s_i = m * (1 + r * p)        # 단리계산
    return s_i

def compound_interest(m, p, r):    # 복리 : 원금, 기간(년), 이자율(년, %)
    r = r / 100
    p_i = m * ((1 + r) ** p)   # 복리계산
    return p_i


money = int(input('원  금 : '))
rate = float(input('이자율 : '))   
period = 10    # 기간(년)

s_i = simple_interest(money, period, rate)     # 단리 계산
p_i = compound_interest(money, period, rate)   # 복리 계산

s_i2 = int(round(s_i, 0))                      # 소수점 첫째 자리 반올림(round, 0) 해서 소수점 윗자리만 
p_i2 = int(round(p_i, 0))

# print(money, s_i, s_i2, p_i, p_i2)
print(f"원금={money:,} 단리={s_i2:,} 복리={p_i2:,}")   # 출력

결과

원  금 : 10000
이자율 : 2
원금=10,000 단리=12,000 복리=12,190
728x90
반응형

댓글