Functions practice makes perfect


#1

I’m not quite sure why this doesn’t work and I’ve gotten a bunch of errors for stuff like this. Please help.

  1. def cube(number):

  2. return number ** 2
    
  3. def by_three(number):

  4. if number % 3 == 0:

  5.  return number/3
    
  6. else

  7.  return "false":
    

it returns error “expected an indented block on line 6”


#2

The name of a function will generally tell a reader what the function does. Above in the header (or signature) line, the name is cube which suggests the return value will the cube of the argument.

Your return line from that function does not seem to agree with my observation.

This is where we are supposed to call the cube() function with number as the argument.

The colon belongs on the else: and a boolean is not a string. In Python it’s either True or False, no quotes.


#3

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