Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/287.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
Python Else语句始终在执行_Python_Python 3.x_Tkinter - Fatal编程技术网

Python Else语句始终在执行

Python Else语句始终在执行,python,python-3.x,tkinter,Python,Python 3.x,Tkinter,我的函数总是运行else语句,即使它显然满足if语句。答案是一个text.get()从tkinter文本框返回 def A1Next(Answer): print(Answer) Answer = str(Answer) if Answer == str('print("Hello World!")') or Answer == str("print('Hello World!')"): print("Correct") else:

我的函数总是运行else语句,即使它显然满足if语句。答案是一个text.get()从tkinter文本框返回

def A1Next(Answer):
    print(Answer)
    Answer = str(Answer)
    if Answer == str('print("Hello World!")') or Answer == str("print('Hello World!')"):
        print("Correct")
    else:
        print("Incorrect")
编辑:下面是提供函数的代码段,用户回答的问题是“在python 3.4.4中打印“Hello World!”的命令是什么?”


Answer1.get(“1.0”,“end”)
将返回以换行符结尾的值。您要将其与之进行比较的值不会以换行结束,因此比较将始终失败

不需要调用
str()
,因为
“…”
的类型已经是
str
。可以删除对
str()
的所有调用。此外,如果
中的两个检查相同,请尝试
print()
调用传递到函数中的值。“这是什么?”伊萨克说。第二行。您的函数为此函数调用正确打印;A1Next(‘世界你好!’)打印)
Q1Title = ttk.Label(Quframe, text = "Question 1", font = ('Helvetica', 10, 'bold'))
Q1Title.grid(row = 0, column = 1, columnspan = 3, stick = 'nsew', padx = 10, pady = 10)
Q1Label = ttk.Label(Quframe, text = "What is the command to print 'Hello World!' in python 3.4.4?", font = ('Helvetica', 10, 'bold')) ##Question user must answer
Q1Label.grid(row = 1, column = 1, columnspan = 3, stick = 'nsew', padx = 10, pady = 10)
# Text box in Window 1
Q1Instructlabel = ttk.Label(Resframe, text = "Enter response below", font = ('Helvetica', 10, 'bold'))
Q1Instructlabel.grid(row = 0, column = 0, columnspan = 3, stick = 'nesw', padx = 10, pady = 10)
Answer1 = Text(Resframe, width = 40, height = 10)
Answer1.grid(row = 1, column = 1, columnspan = 3, stick = 'nsew', padx = 10, pady = 10)
Quitbutton = ttk.Button(Menuframe, text = "Cancel", command = lambda: Window1.destroy()) #Back and next buttons
Quitbutton.grid(row = 0, column = 1, columnspan = 1, stick = 'nsew', padx = 10, pady = 10)
Nextbutton = ttk.Button(Menuframe, text = "Next", command = lambda: A1Next(Answer1.get("1.0", "end"))) #Passes Info to function
Nextbutton.grid(row = 0, column = 3, columnspan = 1, stick = 'nsew', padx = 10, pady = 10)