python入门, name ‘aaa' is not defined这个怎么解决

simle微笑 2014-08-12 06:32:08
#!/usr/bin/python$
2 #-*-coding: utf8 -*-$
3 $
4 s = input("input your name:")$
5 print "hello,%s" %s$



在linux终端运行 python ./hello.py
结果是:
[wenwen@ht ~]$ python ./hello.py
input your name:aaa
Traceback (most recent call last):
File "./hello.py", line 4, in <module>
s = input("input your name:")
File "<string>", line 1, in <module>
NameError: name 'aaa' is not defined
[wenwen@ht ~]$
...全文
29364 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
good8888job 2017-01-05
  • 打赏
  • 举报
回复
引用 9 楼 xuqi7 的回复:
用raw_input() 完美解决
xuqi7 2015-12-10
  • 打赏
  • 举报
回复
用raw_input() 完美解决
Falleyes 2015-03-04
  • 打赏
  • 举报
回复
这个板块主要是C\C++,建议楼主去这里问: CSDN > CSDN论坛 > 其他开发语言 > 脚本语言(Perl ,Python)
baidu_26312751 2015-03-04
  • 打赏
  • 举报
回复
name = raw_input ("Input your name:") print "Hello," + name
simle微笑 2014-08-13
  • 打赏
  • 举报
回复
我是在命令行运行的的确是输入字母就会报错,,, [wenwen@ht ~]$ python hello.py input your name:23 hello,23 [wenwen@ht ~]$ python hello.py input your name:kls Traceback (most recent call last): File "hello.py", line 4, in <module> s = input("input your name:") File "<string>", line 1, in <module> NameError: name 'kls' is not defined [wenwen@ht ~]$ 我的hello.py 就是这样子的:
s = input("input your name:")$
   print ("hello,%s" %s)$
[/quote]
simle微笑 2014-08-13
  • 打赏
  • 举报
回复
引用 4 楼 a350277864 的回复:

>>> s = input("input your name:")
input your name:llq
>>> print ("hello ,%s" % s)
hello ,llq
>>> 
这样的
我是在命令行运行的的确是输入字母就会报错,,, [wenwen@ht ~]$ python hello.py input your name:23 hello,23 [wenwen@ht ~]$ python hello.py input your name:kls Traceback (most recent call last): File "hello.py", line 4, in <module> s = input("input your name:") File "<string>", line 1, in <module> NameError: name 'kls' is not defined [wenwen@ht ~]$ 我的hello.py 就是这样子的:
s = input("input your name:")$
  5 print ("hello,%s" %s)$
千年捞菜 2014-08-13
  • 打赏
  • 举报
回复

>>> s = input("input your name:")
input your name:llq
>>> print ("hello ,%s" % s)
hello ,llq
>>> 
这样的
神奕 2014-08-13
  • 打赏
  • 举报
回复
输入的是数字还是字母又有什么关系呢,python是动态类型的

s = input("input your name:")
print('hello,', s)
simle微笑 2014-08-13
  • 打赏
  • 举报
回复
引用 1 楼 lisong694767315 的回复:
去学学Python的基本语法吧。。。。。。。

s = input("input your name:")
print(s)
我的那个代码 提示输入name时候,接收数字就可以正常, 只要输入字母才会报错,我想知道原因, 想让他最后输出的是: hello,aaa
神奕 2014-08-12
  • 打赏
  • 举报
回复
去学学Python的基本语法吧。。。。。。。

s = input("input your name:")
print(s)

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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