Python Raw_Input() 未定义

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35168508/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 16:05:13  来源:igfitidea点击:

Raw_Input() Is Not Defined

pythonundefinedraw-input

提问by Makailah Morris

I'm a seventh grade programmer so I may be missing a lot of things in this program, but for my coding club my instructor asked us to make a guess the number game. I have very limited knowledge on this subject, since I've only attended four classes. Anyway, when I run this program in Python IDLE 3.5 this is what it says:

我是一名七年级程序员,所以我可能在这个程序中遗漏了很多东西,但是对于我的编码俱乐部,我的老师让我们猜数字游戏。我对这个主题的了解非常有限,因为我只参加过四节课。无论如何,当我在 Python IDLE 3.5 中运行这个程序时,它是这样说的:

Traceback (most recent call last):
File "C:\Users\morrris\AppData\Local\Programs\Python\Python35-32\guess_that_number.py", line 7, in <module>
name= raw_input()
NameError: name 'raw_input' is not defined

I tried changing the code, but it seems to not like the raw_input().

我尝试更改代码,但它似乎不喜欢 raw_input()。

回答by heinst

For Python 3.x, use input(). For Python 2.x, use raw_input(). Don't forget you can add a prompt string in your input()call to create one less print statement. input("GUESS THAT NUMBER!").

对于 Python 3.x,使用input(). 对于 Python 2.x,使用raw_input(). 不要忘记您可以在input()调用中添加一个提示字符串来创建一个更少的打印语句。input("GUESS THAT NUMBER!").