✏️데이터 취업 스쿨 스터디 노트(복습_파이썬 중급 문풀 ①)

Cheon Bumin·2023년 12월 6일

Study Note✏️

목록 보기
6/17

오늘 공부 요약짤...🥲

📑파이썬 코드 살펴보기

함수 (42번)

childPrice = 18000
infantRprice = 25000
adultRprice = 50000
specialDC = 50

def formatedNumber(n) :
    return format(n, ',')
    
def airplaneReceipt(c1, c2, i1, i2, a1, a2) :
    print('=' * 60)
    cp = childPrice * c1
    cp_dc = int((childPrice * c2) * 0.5)
    print(f' 유아 {c1}명 요금 : {formatedNumber(cp)}원')
    print(f' 유아 할인 대상 {c2}명 요금 : {formatedNumber(cp_dc)}원')

    ip = infantRprice * i1
    ip_dc = int((infantRprice * i2) * 0.5)
    print(f' 소인 {i1}명 요금 : {formatedNumber(ip)}원')
    print(f' 소인 할인 대상 {i2}명 요금 : {formatedNumber(ip_dc)}원')

    ap = adultRprice * a1
    ap_dc = int((adultRprice * a2) * 0.5)
    print(f' 대인 {a1}명 요금 : {formatedNumber(ap)}원')
    print(f' 대인 할인 대상 {a2}명 요금 : {formatedNumber(ap_dc)}원')
    print('=' * 60)

    total = c1 + c2 +i1 + i2 + a1 +a2
    totalPrice = cp + cp_dc + ip +ip_dc +ap +ap_dc
    print(f'Total : {formatedNumber(total)}명')
    print(f'TotalPrice : {formatedNumber(totalPrice)}원')
    print('=' * 60)


child = int(input('유아 인원수 : '))
discChild = int(input('할인 대상 유아 인원수 : '))
infant = int(input('소아 인원수 : '))
discInfant = int(input('할인 대상 소아 인원수 : '))
adult = int(input('성인 인원수 : '))
discAdult = int(input('할인 대상 성인 인원수 : '))


airplaneReceipt(child, discChild, infant, discInfant, adult, discAdult)
⭐
- 숫자에 ,을 찍고 싶을 때 format(n, ',') 함수 잊지 말기

함수 (43번)

<내가 작성한 코드>
def formatNum(n) :
    return format(n, ',')

def monthRate (money, year, yearRate) :
    rate = yearRate / 12
    month = year * 12
    totalMoney = money
    moneyRate = 0
    n =0

    while True :
        moneyRate = money * (rate / 100)
        totalMoney += moneyRate
        money = totalMoney

        if n == month-1 :
            break

        n += 1

    return int(totalMoney)

def culculation (money, year, rate) :
    print('[단리 계산기]')
    print('=' * 60)
    print(f'예치금 : {formatNum(money)}원')
    print(f'예치기간 : {year}년')
    print(f'연 이율 : {rate}%')
    print('-' * 60)

    getMoney = int(money + (money * (rate / 100) * year))
    print(f'{year}년 후 총 수령액 : {formatNum(getMoney)}원')
    print('=' * 60)

    print('[월복리 계산기]')
    print('=' * 60)
    print(f'예치금 : {formatNum(money)}원')
    print(f'예치기간 : {year}년')
    print(f'연 이율 : {rate}%')
    print('-' * 60)

    print(f'{year}년 후 총 수령액 : {formatNum(monthRate(money, year, rate))}원')
    print('=' * 60)


money = int(input('예치금(원) : '))
year = int(input('예치 기간 : '))
yearRate = int(input('연 이율(%) : '))

culculation(money, year, yearRate)
<문제 풀이 강의>
# 단리 계산기
def singleRateCalculator(m, t, r):
    totalMoney = 0
    totalRateMoney = 0

    for i in range(t):
        totalRateMoney += m * (r * 0.01)

    totalMoney = m + totalRateMoney
    return int(totalMoney)


# 월복리 계산기
def multiRateCalculator(m, t, r):

    t = t * 12
    rpm = (r / 12) * 0.01
    totalMoney = m

    for i in range(t):
        totalMoney += totalMoney * rpm

    return int(totalMoney)



money = int(input('예치금(원): '))
term = int(input('기간(년): '))
rate = int(input('연 이율(%): '))

print()
print('[단리 계산기]')
print('=' * 30)
print(f'예치금\t: {formatedNumber(money)}원')
print(f'예치기간\t: {term}년')
print(f'연 이율\t: {rate}%')
print('-' * 30)
amount = formatedNumber(singleRateCalculator(money, term, rate))
print(f'{term}년 후 총 수령액: {amount}원')
print('=' * 30)


print()
print('[월복리 계산기]')
print('=' * 30)
print(f'예치금\t: {formatedNumber(money)}원')
print(f'예치기간\t: {term}년')
print(f'연 이율\t: {rate}%')
print('-' * 30)
amount = formatedNumber(multiRateCalculator(money, term, rate))
print(f'{term}년 후 총 수령액: {amount}원')
print('=' * 30)
⭐
- (나) 복리계산과 계산기 템플릿을 함수화
- (강의) 단리, 월복리 계산을 함수화

하루 공부를 마치며🔥

  • 오늘 학습 시간 : 3시간 46분
  • 하려고 한 양은 무조건 하는 습관을 들이자!!
profile
포기만 하지 말자

0개의 댓글