学python遇到的错误

来源:互联网 发布:阿里云网络接入商名称 编辑:程序博客网 时间:2024/06/06 08:38
catNames=[]while True:    print ('enter the name of cat '+str(len(catNames)+1)+ '(Or enter nothing to stop.):')    name=input()    if name=='':        break    catNames=catNames+[name]print ('The cat names are:')for name in catNames:    print (''+name)这段代码运行的时候会出现enter the name of cat 1(Or enter nothing to stop.):TomTraceback (most recent call last):  File "F:/PyCharmProject/Helloworld.py", line 4, in <module>    name=input()  File "<string>", line 1, in <module>NameError: name 'Tom' is not defined这种错误,是因为name=input()这句话,input()只能用于输入数字,改成raw_input()就可以了。
原创粉丝点击