This looks like a really good first attempt! A few suggestions: You could make the stack a class and make peek(), pop() and push() methods on it instead of passing the stack to each function. (For extra complexity points, you can even replace disp() with a __repr__ method).
We also want to wrap your while loop in a main() function and use the standard if __name__ == '__main__' convention -- you can see an example of that here. This'll stop your code from being run from outside this script, preventing other things messing with it's runtime. (It's just generally good practice)
This looks like a really good first attempt! A few suggestions: You could make the stack a class and make
peek()
,pop()
andpush()
methods on it instead of passing the stack to each function. (For extra complexity points, you can even replacedisp()
with a__repr__
method).We also want to wrap your while loop in a
main()
function and use the standardif __name__ == '__main__'
convention -- you can see an example of that here. This'll stop your code from being run from outside this script, preventing other things messing with it's runtime. (It's just generally good practice)