-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_calculator.py
More file actions
27 lines (27 loc) · 849 Bytes
/
simple_calculator.py
File metadata and controls
27 lines (27 loc) · 849 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
def sum(x, y):
return (x+y)
def sub(x, y):
return (x - y)
def arithmetic_ops(op):
num1 = int(input("Input number1: "))
num2 = int(input("Input number2: "))
return num1, num2, op(num1, num2)
while True:
op = input("Input operater ('+','-','*','/','%','end'): ")
if op == '+':
num1, num2, ret = arithmetic_ops(sum)
elif op == '-':
num1, num2, ret = arithmetic_ops(sub)
elif op == '*':
num1, num2, ret = arithmetic_ops(lambda x, y: x*y)
elif op == '/':
num1, num2, ret = arithmetic_ops(lambda x, y: x/y)
elif op == '%':
num1, num2, ret = arithmetic_ops(lambda x, y: x%y)
elif op == "end":
break
else:
print("Invalid operation")
continue
print(f"{num1} {op} {num2} = {ret}")
print("프로그램 종료")