| Conditions | 7 |
| Total Lines | 20 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | def digit_stack(commands): |
||
| 2 | stack = [] |
||
| 3 | sum_of_commands = 0 |
||
| 4 | for i in commands: |
||
| 5 | cmd = i.split() |
||
| 6 | if cmd[0] == 'PUSH': |
||
| 7 | stack.append(int(cmd[1])) |
||
| 8 | elif cmd[0] == 'POP': |
||
| 9 | try: |
||
| 10 | tmp = stack.pop() |
||
| 11 | except IndexError: |
||
| 12 | tmp = 0 |
||
| 13 | sum_of_commands += tmp |
||
| 14 | elif cmd[0] == 'PEEK': |
||
| 15 | try: |
||
| 16 | tmp = stack[-1] |
||
| 17 | except IndexError: |
||
| 18 | tmp = 0 |
||
| 19 | sum_of_commands += tmp |
||
| 20 | return sum_of_commands |
||
| 21 | |||
| 47 |