diff options
| author | Abigail <abigail@abigail.be> | 2021-01-12 17:35:08 +0100 |
|---|---|---|
| committer | Abigail <abigail@abigail.be> | 2021-01-12 18:10:06 +0100 |
| commit | c9cd319243d636baa71d50255bc4f0c71c2c2892 (patch) | |
| tree | 9fc062517077a05f19ea1337fe8dfd0bb96ac52d /challenge-095/abigail/python/ch-2.py | |
| parent | 9af685c4d60cc554406827da104fc2df5078ae99 (diff) | |
| download | perlweeklychallenge-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.py | 27 |
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 |
