一个python问题

dadiguamaomao 2013-10-08 10:48:31
import string

alphas = string.letters + '_'
num = string.digits

print ('welcome version 1.0')
print ('testee must at least two chars')

myInput = input('Identify to test?')

if len(myInput) > 1:

if myInput [0] not in alphas :
print '''("invalid: first symbol must be
alphas")'''
else :
for otherChar in myInput[1:]:
if otherChar not in alphas + num :
print '''("invalid: remaining
symbol must be alphanumic")'''
break
else :
print ("okay as an identifier")
出现这样的错误
SyntaxError: multiple statements found while compiling a single statement
求大神帮助
...全文
11696 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
dadiguamaomao 2013-10-09
  • 打赏
  • 举报
回复
引用 7 楼 snmr_com 的回复:
你要看书是什么时候出的,应用在python哪个版本才对,版本不同,语法解析就有区别 python2转到python3不仅仅是软件升级那么简单,语法已经有质的不同了 multiple statements found while compiling a single statement 的意思大概是多个语句写在同一行,不一定是你写/抄错了,可能用了不同的版本,解析出来就出问题了
我的是3.3.2版本按照你的样子改了,我是新建new window里编写的,为什么run Module不能提示错误原因呢
ImN1 2013-10-09
  • 打赏
  • 举报
回复
例如python3并没有string.letters,而是string.ascii_letters 忘了一点,你是整段copy到 IDLE么? 这样貌似就符合那个出错信息了 这样不行,要逐行输入,或者先写到一个文件,IDLE加载进来再run
ImN1 2013-10-09
  • 打赏
  • 举报
回复
你要看书是什么时候出的,应用在python哪个版本才对,版本不同,语法解析就有区别 python2转到python3不仅仅是软件升级那么简单,语法已经有质的不同了 multiple statements found while compiling a single statement 的意思大概是多个语句写在同一行,不一定是你写/抄错了,可能用了不同的版本,解析出来就出问题了
dadiguamaomao 2013-10-09
  • 打赏
  • 举报
回复
引用 5 楼 snmr_com 的回复:
如果是3.x print '''("invalid: first symbol must be alphas")''' 这样写应该不行,print是函数形式 最大问题是怎么有两个同级缩进的 else?
这是python核心编程上的例子,我是照着例子写的,但是就是有错,没有提示错误在哪一行
ImN1 2013-10-09
  • 打赏
  • 举报
回复
如果是3.x print '''("invalid: first symbol must be alphas")''' 这样写应该不行,print是函数形式 最大问题是怎么有两个同级缩进的 else?
dadiguamaomao 2013-10-09
  • 打赏
  • 举报
回复
引用 2 楼 iasky 的回复:
myInput = input('Identify to test?') 这句比较关键,你的是Python 2.x还是3.x,是2.x就有问题raw_input
3.3.2版本 我是在IDLE下新建一个窗口,但是运行时候不知道如何使它弹出错误信息
panghuhu250 2013-10-09
  • 打赏
  • 举报
回复
怎样读错误信息: ~/bin/ python /tmp/xx.py welcome version 1.0 testee must at least two chars Identify to test?abc Traceback (most recent call last): File "/tmp/xx.py", line 9, in <module> myInput = input('Identify to test?') File "<string>", line 1, in <module> NameError: name 'abc' is not defined 这是出问题的代码所在文件, 这是行号, in <module> 这是具体代码 这是错误信息
iasky 2013-10-09
  • 打赏
  • 举报
回复
myInput = input('Identify to test?') 这句比较关键,你的是Python 2.x还是3.x,是2.x就有问题raw_input
panghuhu250 2013-10-09
  • 打赏
  • 举报
回复
错误在哪一行,相关代码是什么?

37,719

社区成员

发帖
与我相关
我的任务
社区描述
JavaScript,VBScript,AngleScript,ActionScript,Shell,Perl,Ruby,Lua,Tcl,Scala,MaxScript 等脚本语言交流。
社区管理员
  • 脚本语言(Perl/Python)社区
  • IT.BOB
加入社区
  • 近7日
  • 近30日
  • 至今

试试用AI创作助手写篇文章吧