Discuss / Python / 大哥救命 这是什么毛病

大哥救命 这是什么毛病

Topic source

我的代码:

name = input('please input your name: ')

print('Hello ', name)

我是在本机练习的 之前练习name = input()的时候 在下面直接输入 例如:test

则会提示:

Traceback (most recent call last):

  File "hello.py", line 1, in <module>

    name = input()

  File "<string>", line 1, in <module>

NameError: name 'test' is not defined

奇怪 我明明是在命名为什么会去查找 后来我以为是因为字符串要加单引号'' 结果正常数出了 我以为大佬事例里面忘记打了就过去了 但是在最开头的代码里 我如果直接输入英文则会报上面的错误,如果我加上单引号又会直接输出

('Hello ', 'test')

我才觉得我从第一个练习就出现了问题   请救救孩子

你是不是没有设置字符集啊?

你的代码有这样一行吗?

# -*- coding: UTF-8 -*-

少主病

#3 Created at ... [Delete] [Delete and Lock User]

我也是这样 求指教

Eden小超

#4 Created at ... [Delete] [Delete and Lock User]

这个是要把你前两行代码用编辑器保存成.py的文件然后用命令模式打开这个文件就可以了

Summery--__--

#5 Created at ... [Delete] [Delete and Lock User]

我和你遇到同样的问题。后来发现是因为我的电脑默认用python 2.x版本来运行的。如果你电脑有多个版本的python,那么你在运行程序的时候,把命令 >> python xxx.py 改成 >> python3 xxx.py试试。

王一二_biu

#6 Created at ... [Delete] [Delete and Lock User]

name = input('please input your name: ')

print('Hello ', name)

把这两行代码放在文本编辑器中,保存为hello.py

然后python hello.py

看看输入法是不是英文的?


  • 1

Reply