Why wont this work?


#1

def cube(number):
   return (number, cubed)
def by_three(number):
      if n % 3 == 0 
return n % 3 = cube(number):
      else: by_three = False

#2

because this code is full of syntax errors?

a cube of a number is to the power of 3 so for example:

3 ^ 3 = 27

you have to write this in programming syntax, and then return it. That is your cube function.

then here:

if n % 3 == 0

missing colon at this line, and where is n coming from?

can you provide the exercise url? i need to see what needs to be done

this line:

return n % 3 = cube(number):

the indention is of, the syntax looks weird. the remainder of n divided by 3 should get a value of cube number, that is not possible. you can assign like that. What is the colon doing in this line? here:

else: by_three = False

you set a function to false?


#3

#4

i was right here:

apply this change, and this one:

then here:

return n % 3 = cube(number):

this line should be inside the if clause (indention), and return cube(number)

then here:

else: by_three = False

you should return false, not set the function to false

If you nee more help, post an updated version of your code


#5

extra indent...

should be...

else:
    by_three = False

#6

it is technically not wrong, but having 4 spaces indent in cube and 8 in by_three is not neat either, but then specify it as recommendation.

no, you can do:

else: by_three = False

python allows for this, if you have a single line for your else clause, you can put it on the same line as the else keyword, if you wanted to you could even do:

return False if n%3 else cube(number)

perfectly valid, even shorter and even less lines


#7

Thank you all I will try and report what happens


#8

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