<문제>
https://www.codetree.ai/missions/5/problems/quadratic-operations-function/submissions
코드트리 | 코딩테스트 준비를 위한 알고리즘 정석
국가대표가 만든 코딩 공부의 가이드북 코딩 왕초보부터 꿈의 직장 코테 합격까지, 국가대표가 엄선한 커리큘럼으로 준비해보세요.
www.codetree.ai
<풀이>
1. 사칙연산을 함수화시켜 출력
2. 다른 op가 들어올 경우 "False"로 예외처리
def addFunc(n1, n2):
return n1 + n2
def subFunc(n1, n2):
return n1 - n2
def mulFunc(n1, n2):
return n1 * n2
def divFunc(n1, n2):
return n1 // n2
n1, op, n2 = input().split()
result = 0
if op == '+':
result = addFunc(int(n1), int(n2))
elif op == '-':
result = subFunc(int(n1), int(n2))
elif op == '*':
result = mulFunc(int(n1), int(n2))
elif op == '/':
result = divFunc(int(n1), int(n2))
if op == '+' or op == '-' or op == '*' or op == '/':
print(n1, op, n2, '=', result)
else:
print(False)
'코드트리 알고리즘 > Python' 카테고리의 다른 글
[코드트리] 그 계절, 그 날 - Python (0) | 2023.08.31 |
---|---|
[코드트리] 함수를 이용한 369 게임 - Python (0) | 2023.08.31 |