Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/357.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 3.3_Python - Fatal编程技术网

输入错误Python 3.3

输入错误Python 3.3,python,Python,每当我使用下面的代码时,它都会给我一个语法错误 print('1. Can elephants jump?') answer1 = input() if answer1 = 'yes': print('Wrong! Elephants cannot jump') if answer1 = 'no': print('Correct! Elephants cannot jump!' 我相信这与字符串有关,不能等于什么?您正在使用赋值(one=)而不是相等测试(double=

每当我使用下面的代码时,它都会给我一个语法错误

    print('1. Can elephants jump?')
answer1 = input()
if answer1 = 'yes':
    print('Wrong! Elephants cannot jump')
if answer1 = 'no':
    print('Correct! Elephants cannot jump!'
我相信这与字符串有关,不能等于什么?

您正在使用赋值(one
=
)而不是相等测试(double
=
):

=
加倍到
=

if answer1 = 'yes':
if answer1 == 'yes':

您还缺少一个右括号:

print('Correct! Elephants cannot jump!'

在末尾添加缺少的

您在最后一次打印时缺少一个右括号:

print('Correct! Elephants cannot jump!')
#                                here--^
此外,您需要使用
=
进行比较测试,而不是
=
(用于变量赋值)

最后,您应该使用
elif
来测试一件事或另一件事

更正代码:

print('1. Can elephants jump?')
answer1 = input()
if answer1 == 'yes':
    print('Wrong! Elephants cannot jump')
elif answer1 == 'no':
    print('Correct! Elephants cannot jump!')

使用==进行比较。Not=,这是用于赋值的


你可能还想检查一下你的()

在你的帖子中发布错误消息总是一个好主意。你的第一行有一个
缩进错误
,这甚至阻止你进入第一个
语法错误
。谢谢,我要求一个更正,得到了3个,谢谢你的帮助!
print('Correct! Elephants cannot jump!')
#                                here--^
print('1. Can elephants jump?')
answer1 = input()
if answer1 == 'yes':
    print('Wrong! Elephants cannot jump')
elif answer1 == 'no':
    print('Correct! Elephants cannot jump!')