Does the function exercise asking users to find the cube root want an if-else sstatement for both functions?


Please leave the following link in the post so we can find the unit module, else replace it with a link to the exact lesson:

Strings and Console Output


No. Only the by_three function has a conditional. The cube function is pure. Value in -> cubed value out.

def cube(number):
  return number ** 3

def by_three(number):
  if number % 3 == true
  return cube(number)
  else: return Fale

In regards to strict equality (===)
Why does the hint state:

if n % 3 == 0:
  print "n is divisible by 3"
  print "n is not"
Make sure both functions return their values rather than printing them.

Both branches of the if/else statement in by_three need to have return statements in them (that's three returns total, two for by_three and one for cube).

Most importantly, did I call the function within a function the right way - I undertand there are no global variables in python.


I’m taking a break for a bit now will be back later.


That line can be removed.

Missing colon to open code block.

Missing indentation.

Misspell… False

We call a function from within a function the same as we would in any situation. What is happening here is,

1. call to cube with number as argument
2. cube function returns a cubed value
3. by_three function returns that value.

There are globals in Python, but prudent writing avoids the use of them as much as possible.


if something == True:

is the same as,

if something:

When something evaluates to True (or is a boolean already) it will pass.


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