(중급) problems

임경민·2023년 9월 25일
1
post-thumbnail
post-custom-banner

Summarization


  • Python 중급 문제풀이
  • 함수, 모듈 문제풀이 진행

Contents


함수

  • 단리계산
def singleRateCalculator(m, t, r): # 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
    rateForMonth = (r / 12) * 0.01
    
    totalMoney = m
    for i in range(t):
        totalMoney *= totalMoney * rateForMonth
        
    return int(totalMoney)

모듈

Arithmetic

  • Basic operator
# basic_operator

def add(n1, n2):
    return round(n1 + n2, 2)

def sub(n1, n2):
    return round(n1 - n2, 2)

def mul(n1, n2):
    return round(n1 * n2, 2)

def div(n1, n2):
    return round(n1 / n2, 2)
  • Developer operator
# developer_operator

def mod(n1, n2):
    return round(n1 % n2, 2)

def flo(n1, n2):
    return round(n1 // n2, 2)

def exp(n1, n2):
    return round(n1 ** n2, 2)

Shape

  • Triangle, Square Area
# triangle_square_area

def calTriangleArea(width, height):
    return round(width * height / 2, 2)

def calSquareArea(width, height):
    return round(width * height, 2)
  • Circle Area
# circle_area

def calCircleArea(r):
    pi = 3.14
    return round(r ** 2 * pi, 2)
  • 실행코드
    만들어진 모듈에서 사용하고자 하는 함수를 불러올 것.
from arithmetic import basic_operator as bo
from arithmetic import developer_operator as do
from shape import triangle_square_area as tsa
from shape import circle_area as ca

inputNumber1 = float(input('숫자 1 입력: '))
inputNumber2 = float(input('숫자 2 입력: '))
post-custom-banner

0개의 댓글