Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Whenever I use the following code, it gives me a syntax error.

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

I believe it has something to do with a string cannot be equal something?

share
2  
It is always a good idea to post the error messages in your post too –  Acyclic Tau 2 mins ago

3 Answers

You are using assignment (one =) instead of equality testing (double ==):

if answer1 = 'yes':

and

if answer1 = 'no':

Double the = to ==:

if answer1 == 'yes':

and

if answer1 == 'no':

You are also missing a closing parenthesis:

print('Correct! Elephants cannot jump!'

Add the missing ) at the end.

share

You are missing a closing parenthesis at the last print:

print('Correct! Elephants cannot jump!')
#                                here--^

Also, you need to use == for comparison tests, not = (which is for variable assignment).

Finally, you should use elif to test for 1 thing or another.

Corrected code:

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

Use == for comparison. Not = , that is for assignment.

You may also want to check your ()

share

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.