zoukankan      html  css  js  c++  java
  • stack.py

     1 #!/usr/bin/env python
     2 stack = []
     3 
     4 def pushit():
     5     stack.append(raw_input(' Enter New String: ').strip())
     6 
     7 def popit():
     8     if len(stack) == 0:
     9         print 'Cannot pop from an empty stack!'
    10     else:
    11         print 'Removed [', `stack.pop()`, ']'
    12 
    13 def viewstack():
    14     print stack
    15 
    16 CMDs = {'u': pushit, 'o':popit, 'v':viewstack}
    17 def showmenu():
    18 
    19     pr="""
    20     P(U)sh
    21     p(O)p
    22     (V)iew
    23     (Q)uit
    24     
    25 Enter choice:"""
    26 #注意下面第一个while和上面的pr对齐
    27     while True:
    28 
    29         while True:
    30 
    31             try:
    32 
    33                 choice = raw_input(pr).strip()[0].lower()
    34             except (EOFError, KeyboardInterrupt, IndexError):
    35                 choice = 'q'
    36 
    37             print '
     You picked: [%s]' % choice
    38             if choice not in 'uovq':
    39 
    40                 print 'Invalid option, try again'
    41             else:
    42                 break
    43 
    44         if choice == 'q':
    45 
    46             break
    47         CMDs[choice]()
    48 if __name__ == '__main__':
    49     showmenu()

    NameError: name 'pr' is not defined

    当出现此错误时,需注意的是将第一个while与上面的pr对齐。

  • 相关阅读:
    HTML静态网页--JavaScript-简介
    html 表单 css样式表
    html 表格 嵌套 frameset 热点
    触发器
    存储过程 if 复习 while 学习
    变量运算符
    SQL数学函数
    SQL数据库基础
    批處理文章引用
    对Excel操作(VBA)
  • 原文地址:https://www.cnblogs.com/xyu1/p/7764611.html
Copyright © 2011-2022 走看看