GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — article/corepython2ndsourcecode/ch06/stack.py at master · pythonpeixun/article Expand file tree/ Copy pathstack.pyMore file actions 66 lines (51 loc) · 1.25 KB / Copy pathstack.pyFile metadata and controls66 lines (51 loc) · 1.25 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 #!/usr/bin/env python # coding:utf-8 ''' 欢迎参加黄哥python远程视频培训, 帮你完成从不会写代码到会写代码解决问题的过渡。 https://github.com/pythonpeixun/article/blob/master/index.md 咨询qq:1465376564 黄哥Python培训 黄哥改写 Python 3 P145页代码 ''' stack = [] def pushit(): stack.append(input('Enter new string: ')) def popit(): if len(stack) == 0: print('Cannot pop from an empty stack!') else: print('Removed [', stack.pop(), ']') def viewstack(): print(str(stack)) def showmenu(): prompt = """ p(U)sh p(O)p (V)iew (Q)uit Enter choice: """ done = 0 while not done: chosen = 0 while not chosen: try: choice = input(prompt)[0] except (IndexError, EOFError, KeyboardInterrupt): choice = 'q' print('\nYou picked: [%s]' % choice) if choice not in 'uovq': print('invalid option, try again') else: chosen = 1 if choice == 'q': done = 1 if choice == 'u': pushit() if choice == 'o': popit() if choice == 'v': viewstack() if __name__ == '__main__': showmenu() |
| You are visitor 01402520 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |