The Big If syntax error


#1

https://www.codecademy.com/courses/python-beginner-BxUFN/4/1?curriculum_id=4f89dab3d788890003000096#

No matter what I do, I ALWAYS get this error message.

File "python", line 6
elif (3 + 2 = 6) or (4 > 5):
^
SyntaxError: invalid syntax

# Make sure that the_flying_circus() returns True
def the_flying_circus():
    if  "Yes" == "yes" and "no" == "no":    # Start coding here!
        elif (3 + 2 = 6) or (4 > 5) :
            print "false"
        else:
            print "Nothing"

#2

Are you trying to say whether 2+3 is equal to 6? If so, you should use the == for comparisons. = is for assigning things.
Also, make sure you are returning your results and not printing them. As that's what the instructions state.
Function must also always return True!

Another thing, when writing conditional statements, always make sure to start with if. Even if it is nested in an if already. Like this:

if ... : 
    if ...:
    elif ...:
    else:
elif ....:
else:

#3

I don't remember being taught anything about a return statement, whatever that is, and I can't get it to work no matter what I try. I always get the syntax error under elif.


#4

Dude, when I did this lesson I used whole numbers instead of words. It's easier for me.
My code, unanswered, is in that order:

# Tenha certeza que the_flying_circus() retorna True
def the_flying_circus():
    if:
        return True
        # o codigo dentro deste bloco!
    elif:
        return True
        # Voce vai querer adicionar tambem a declarao else!
    else:
        print
        print

Ps: Ah ... my native language is Brazilian Portuguese. So I'm sorry for the spelling and also, do not be scared with the comments in Portuguese in my code.


#5

No matter what I try, it always gives me a syntax error at line 3 immediately after "elif"
Nothing I try fixes it. That's also the only error I'm getting.


#6

At least for me, your if elif and else should all be lined up together in spacing. I know datfatcat mentioned something to that effect above but I think he was misled in that. Your code should line up something to this nature.

print the_flying_circus();
def the_flying_circus():
    if the_flying_circus == whatever
        print whatever
    elif whatever
        print whatever
    else:
        print whatever

Notice how the if elif and else all are spaced the same distance from the left hand side of the page and the same is true for your print statements.


#7

Now it's telling me that the_flying_circus() returned value none.

def the_flying_circus():
    if  (10 - 5 == 5) and (2 + 2 == 4):
        print "Hello world."
    elif (3 + 2 == 6) or (4 >= 5) :
        return True
    else:
        return True

#8

Ok good we are making progress! Let me take your code and put it into my lesson and see if I can hash out at least what this new error is coming from. Give me a few minutes to look and if not I can see if someone else with more skill than me can help you haha


#9

Sorry to intrude on your reply @bibleman13 .
The function of your code is right, just make sure you keep the correct pattern like this below.
Follow the example of this code. Note that it's just how the code should be mounted, I will not give the answer.

def the_flying_circus():
    if:
        return True
    elif:
        return True
    else:
        print 
        print

#10

Well I don't mind usually but I am afraid I have found his problem and its not his spacing unfortunately for you. Its actually got to do with his first print statement.

You see in this lesson, according to step 4, you are asked to Finally, the_flying_circus() must return True when evaluated. You see in your code @blogsurfer36193 you printed "Hello World" instead of return True so your code, for your only true statement, did not return True it instead printed nothing or "Hello World". So just replace print "Hello world." with return True from the previous code you gave me and your lesson will be complete! :smiley:


#11

Enjoy your code.

def the_flying_circus():
    if (10 - 5 == 5) and (2 + 2 == 4): 
        return True
    elif: #Do another function, the one you did before will return "False"
        return True
    else:
        print "Ten minus five equals five and two plus two equals four"
        print "#Do the same thing from the print up. Only this impression should print the "elif" "

#12

I've got it now, finally. Thanks guys!


#13

Hm? I merely thought he was doing nested conditions. Therefore even nested ones need to start with if. Like this:

def the_flying_circus():
    if  "Yes" == "Yes" and "no" == "no":    # Start coding here!
        if 3 + 2 == 6 or 4 > 5 :
            return False
        elif 4 == 4:
            return True
        else:
            return "Nothing"
    else:
            return False

Well since it's solved without it, it doesn't matter :stuck_out_tongue:


#14

Yeah I figured that is where you were going but I gathered he didn't understand as such so I tried just a non-nested setup haha :thumbsup:


#15

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.