Хайруллина Алина IterCalc 5904
Тулинова Олеся Вадимовна, 442 группа IterCalc 5200
f1def itercalc():f1def itercalc():
n2    stack_values = []n2    stack = []
3    command = (yield)3    cmd = (yield)
4    while True:4    while True:
n5        if command == '?':n5        if cmd == '?':
6            if stack_values:6            if stack:
7                command = (yield stack_values[-1])7                cmd = (yield stack[-1])
8            else:8            else:
9                print('Insufficient stack')9                print('Insufficient stack')
n10                command = (yield None)n10                cmd = (yield None)
11            continue11            continue
12        try:12        try:
n13            stack_values.append(int(command))n13            stack.append(int(cmd))
14            command = (yield None)14            cmd = (yield None)
15            continue15            continue
16        except Exception:16        except Exception:
17            pass17            pass
n18        if command in {'+', '-', '*', '/'}:n18        if cmd in {'+', '-', '*', '/'}:
19            if len(stack_values) < 2:19            if len(stack) < 2:
20                print('Insufficient stack')20                print('Insufficient stack')
n21                command = (yield None)n21                cmd = (yield None)
22                continue22                continue
n23            operand_b = stack_values.pop()n23            b = stack.pop()
24            operand_a = stack_values.pop()24            a = stack.pop()
25            if command == '+':25            if cmd == '+':
26                result = operand_a + operand_b26                res = a + b
27            elif command == '-':27            elif cmd == '-':
28                result = operand_a - operand_b28                res = a - b
29            elif command == '*':29            elif cmd == '*':
30                result = operand_a * operand_b30                res = a * b
31            elif command == '/':31            elif cmd == '/':
32                if operand_b == 0:32                if b == 0:
33                    print('Zero division')33                    print('Zero division')
n34                    stack_values.extend([operand_a, operand_b])n34                    stack.extend([a, b])
35                    command = (yield None)35                    cmd = (yield None)
36                    continue36                    continue
n37                result = operand_a // operand_bn37                res = a // b
38            stack_values.append(result)38            stack.append(res)
39            command = (yield None)39            cmd = (yield None)
40            continue40            continue
41        print('Unknown command')41        print('Unknown command')
t42        command = (yield None)t42        cmd = (yield None)
Legends
Colors
 Added 
Changed
Deleted
Links
(f)irst change
(n)ext change
(t)op