6. Practice Makes Perfect



File "python", line 7
SyntaxError: invalid syntax

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


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.


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


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.


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.


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


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


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