aboutsummaryrefslogtreecommitdiff
path: root/challenge-095/abigail/python/ch-2.py
diff options
context:
space:
mode:
authorAbigail <abigail@abigail.be>2021-01-12 17:35:08 +0100
committerAbigail <abigail@abigail.be>2021-01-12 18:10:06 +0100
commitc9cd319243d636baa71d50255bc4f0c71c2c2892 (patch)
tree9fc062517077a05f19ea1337fe8dfd0bb96ac52d /challenge-095/abigail/python/ch-2.py
parent9af685c4d60cc554406827da104fc2df5078ae99 (diff)
downloadperlweeklychallenge-club-c9cd319243d636baa71d50255bc4f0c71c2c2892.tar.gz
perlweeklychallenge-club-c9cd319243d636baa71d50255bc4f0c71c2c2892.tar.bz2
perlweeklychallenge-club-c9cd319243d636baa71d50255bc4f0c71c2c2892.zip
Python solution for week 95/part 2
Diffstat (limited to 'challenge-095/abigail/python/ch-2.py')
-rw-r--r--challenge-095/abigail/python/ch-2.py27
1 files changed, 27 insertions, 0 deletions
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