Explain the mistake in the following code


#1

Can you tell me what’s wrong with this one?

def cube(number):
  cubeofnumber = number ** 3
  return cubeofnumber

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

Explain the mistake(s) in the following code:
#2

Incorrect indentation.

You need to indent your code blocks under def, and then indent further under if and else.

Like so:

def cube(number):
  cubeofnumber = number ** 3
  return cubeofnumber

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

#3

@tech-priest, how do you know the indent is wrong? tagcorder posted his code without any markup/format, so the indent didn’t show. Doesn’t mean the indent isn’t there

I added the format, try again :wink:


#4

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