初学python一个细小的问题
#!/user/bin/env python
stack=[]
def pushit ():
stack.append(input('Enter New string:').strip())
def popit ():
if len(stack)==0:
print('Can not pop from an empty stack!')
else:
print('Removes[',stack.pop(),']')
def viewstack():
print (stack)
CMDs={'u':pushit,'o':popit,'v':viewstack}
def showmenu():
pr='''
p(U)sh
p(O)p
(V)iew
(Q)uit
Enter choice:'''
while 1>0:
while 1>0:
try:
choice=input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice='q'
print('\nYou picked:[%s]'%choice)
if choice not in 'uovq':
print('Invalid option,try again')
else:
break
if choice=='q':
break
CMDs[choice]()
if _name_=='_main_':
showmenu()
这样,返回Traceback (most recent call last):
File "E:/Python/菜单驱动.py", line 24, in <module>
choice=input(pr).strip()[0].lower()
NameError: name 'pr' is not defined
请教,怎么改?
stack=[]
def pushit ():
stack.append(input('Enter New string:').strip())
def popit ():
if len(stack)==0:
print('Can not pop from an empty stack!')
else:
print('Removes[',stack.pop(),']')
def viewstack():
print (stack)
CMDs={'u':pushit,'o':popit,'v':viewstack}
def showmenu():
pr='''
p(U)sh
p(O)p
(V)iew
(Q)uit
Enter choice:'''
while 1>0:
while 1>0:
try:
choice=input(pr).strip()[0].lower()
except (EOFError,KeyboardInterrupt,IndexError):
choice='q'
print('\nYou picked:[%s]'%choice)
if choice not in 'uovq':
print('Invalid option,try again')
else:
break
if choice=='q':
break
CMDs[choice]()
if _name_=='_main_':
showmenu()
这样,返回Traceback (most recent call last):
File "E:/Python/菜单驱动.py", line 24, in <module>
choice=input(pr).strip()[0].lower()
NameError: name 'pr' is not defined
请教,怎么改?
...全文
相关推荐
[初学python]一个简单的ATM程序
本文介绍了一个使用Python编写的简易银行账户管理系统。系统通过pickle模块进行账户信息的序列化和反序列化,实现了用户登录、取款、购物、还款和账单查询等功能。用户通过主菜单选择操作,系统会根据用
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
Python初学者需要注意的问题2
Python初学者需要注意的问题
[初学入门]ArcGIS中Python脚本的使用
从Python基础到ArcGIS的集成应用,每一个环节都需要实践和理解,希望这篇初学者指南能帮助你开启GIS编程之旅。随着对Python和ArcGIS的深入,你会发现更多可能,解决更复杂的空间问题。
初学者学习Python好还是Java好
在文章的标题"初学者学习Python好还是Java好"中,我们可以看到作者想要讨论的是初学者在选择编程语言时应该选择Python还是Java。这个问题是很多初学者在学习编程语言时都会遇到的问题。


