본문 바로가기

Python_Beginer/Study

HRD 수업>파이썬을 이용한 자동화 스크립트 - 연습문제 7

반응형
'''
1. 사칙연산 함수를 포함하는 calculator.py를 작성
2. main.py 파일에 main() 함수에서 calculator 모듈을 사용해서 사직 연산을 수행
calculator.py
'''
def add(a, b):
    return a + b
def sub(a, b):
    return a - b
def mul(a, b):
    return a * b
def div(a, b):
    return a / b

def main(a, b):
    print('{0} + {1} = {2}'.format(a, b, add(a, b)),
          '\n{0} - {1} = {2}'.format(a, b, sub(a, b)),
          '\n{0} * {1} = {2}'.format(a, b, mul(a, b)),
          '\n{0} / {1} = {2}'.format(a, b, div(a, b)))

'''
main.py
'''
# import calculator
main(2, 3)

2 + 3 = 5 
2 - 3 = -1 
2 * 3 = 6 
2 / 3 = 0.6666666666666666

Process finished with exit code 0

반응형