输入错误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!')