Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有人能解释一下为什么这个简单的代码没有';你不能在Python2.7中工作吗?_Python_Python 2.7 - Fatal编程技术网

有人能解释一下为什么这个简单的代码没有';你不能在Python2.7中工作吗?

有人能解释一下为什么这个简单的代码没有';你不能在Python2.7中工作吗?,python,python-2.7,Python,Python 2.7,我不得不在编程课上为期中考试编写这段代码,这只是代码的一小部分。 请记住,我对编程非常陌生,这是一个入门课程 我们在课堂上学习3.5,我写的代码在3.5中运行良好。但是,我正开始尝试学习2.7,但这段代码对它不起作用: print ("is student 1 here?") attendence1 = input() if attendence1 == "yes": student1 = "Y" if attendence1 != (str("yes")): student1 = (

我不得不在编程课上为期中考试编写这段代码,这只是代码的一小部分。 请记住,我对编程非常陌生,这是一个入门课程

我们在课堂上学习3.5,我写的代码在3.5中运行良好。但是,我正开始尝试学习2.7,但这段代码对它不起作用:

print ("is student 1 here?")
attendence1 = input()
if attendence1 == "yes":
     student1 = "Y"
if attendence1 != (str("yes")):
student1 = ("N")
我只是好奇不同版本之间的问题是什么,以及3.5是如何读取的,而2.7是如何读取的。我注意到,如果我在2.7中以字符串形式输入答案,它将起作用,即: 学生2在吗? 答:“是的” 不会导致错误,无论如何 学生2在吗? A是的 让它给我

attendence1 = input()
File "<string>", line 1, in <module>
NameError: name 'yes' is not defined
attendence1=input()
文件“”,第1行,在
名称错误:未定义名称“是”
我如何使这段代码在2.7上工作

attendence1 = raw_input("is student 1 here?\n")
if attendence1 == "yes":
    student1 = "Y"
else:
    student1 = "N"

需要使用
原始输入()
而不是输入。另外,我认为您想要的是
“N”
而不是
(“N”)

使用
原始输入
而不是
输入
对于
2.7
请参阅可能的重复谢谢先生!我不确定