6. Practice Makes Perfect


#1



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


File "python", line 7
else:
^
SyntaxError: invalid syntax


def cube(number):
    return number **3
    
def by_three(number):
    if number % 3 == 0:
        return cube(number)
else: 
       return False
    
    print cube(3)
    print by_three(5)


#2

Not sure what you want, could you google for an example of how to do that or is there something stopping you that you want to ask about, and if so, what? Please explain what you want to know.


#3

im sorry, i didnt explain myself, i dont know what the problem is with my code, it returns this
File "python", line 7
else:
^
SyntaxError: invalid syntax
and i dont really get why.


#4

It's pointing at an else, right? How is that normally used, where is it allowed, what do you intend for it to be?

Can you motivate why what you wrote should be right? If so, what's that reasoning, something's got to be off about that and would be worth asking about or researching.

I would be googling for examples of if-else statements to figure this out, since that's what you're trying to do here.

Another approach is to temporarily remove things until the syntax error isn't showing up, and to get that offending part working by itself in isolation of the rest of the code.


#5

Are you getting anywhere?

See, from my perspective the problem isn't the syntax error, but what's stopping you from figuring it out. You will constantly write things incorrectly, so figuring out this particular error is but a drop in the ocean, makes no difference.

Whether trying to find it on your own or asking about it, you will need to establish what information you want and think about how you can get it and what might be stopping you from doing so.


#8

I believe you just need to tab the else: in, directly under the if statement.


#9

Yeah, just put a tab in front of the else.


#10

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