변경이력

돌아가기
2 1개 문자 추가

2017/01/07 09:42

서 현

```{.python} import re def eval(op, variables): variable = list(map(int, variables.split())) if op == '+': out = sum(variable) elif op == '-': out = variable[0] for i in range(2,len(variable)): out -= variable[i] elif op == '*': out = 1 for i in range(len(variable)): out *= variable[i] elif op == '/': out = variable[0] for i in range(2,len(variable)): out /= variable[i] return out def f(input_string): p = re.compile('\(([\+\-\*\/])\s(:?[^\(^\).]+)\)') m = p.search(input_string) out = eval(m.group(1),m.group(2)) output_string = input_string.replace(m.group(), str(out)) try: f(output_string) except: print(output_string) pass input_string = '(* (- 32 3) (- 32 4 8))' f(input_string) ```
```{.python} import re def eval(op, variables): variable = list(map(int, variables.split())) if op == '+': out = sum(variable) elif op == '-': out = variable[0] for i in range(2,len(variable)): out -= variable[i] elif op == '*': out = 1 for i in range(len(variable)): out *= variable[i] elif op == '/': out = variable[0] for i in range(2,len(variable)): out /= variable[i] return out def f(input_string): p = re.compile('\(([\+\-\*\/])\s(:?[^\(^\).]+)\)') m = p.search(input_string) out = eval(m.group(1),m.group(2)) output_string = input_string.replace(m.group(), str(out)) try: f(output_string) except: print(output_string) pass input_string = '(* (- 32 3) (- 32 4 8))' f(input_string) ```
1 Original

2017/01/07 09:42

서 현

코딩도장

코딩도장은 프로그래밍 문제풀이를 통해서 코딩 실력을 수련(Practice)하는 곳입니다.