From c9cd319243d636baa71d50255bc4f0c71c2c2892 Mon Sep 17 00:00:00 2001 From: Abigail Date: Tue, 12 Jan 2021 17:35:08 +0100 Subject: Python solution for week 95/part 2 --- challenge-095/abigail/python/ch-2.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 challenge-095/abigail/python/ch-2.py diff --git a/challenge-095/abigail/python/ch-2.py b/challenge-095/abigail/python/ch-2.py new file mode 100644 index 0000000000..ab91e0303c --- /dev/null +++ b/challenge-095/abigail/python/ch-2.py @@ -0,0 +1,27 @@ +import fileinput +import re + +stack = [] +error = "Stack is empty" +for line in fileinput . input (): + chunks = line . split () + command = chunks [0] + + if command == "push": + stack . append (int (chunks [1])) + + if command == "pop": + if len (stack): + stack . pop () + + if command == "top": + if len (stack): + print stack [len (stack) - 1] + else: + print error + + if command == "min": + if len (stack): + print min (stack) + else: + print error -- cgit