파이썬/exercise
10-1. python 딕셔너리와 함수 결합
태지쌤
2023. 1. 5. 20:00
반응형
def add(n1, n2):
return n1 + n2
def sub(n1, n2):
return n1 - n2
def mul(n1, n2):
return n1 * n2
def div(n1, n2):
return n1 / n2
operations ={
"+":add,
"-":sub,
"*":mul,
"/":div
}
num1 = int(input("첫번째 수를 입력하세요 : "))
for o in operations:
print(o)
operation_symbol = input("연산자를 입력하세요 : ")
num2 = int(input("두번째 수를 입력하세요 : "))
func = operations[operation_symbol]
answer = func(num1, num2)
print(f"{num1} {operation_symbol} {num2} = {answer}")반응형