Function: Practice makes perfect infinite loop error


#1



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


#2

This is the cause. Just, return cube(number).


#3

Thank you! Do you know why? the directions say to have by_three call cube(number) and return its result. Am I misunderstanding what its asking or misunderstanding how to call a function?


#4

When the function makes the call to cube(), that function sends a return value back to the caller. Then it is returned to the by_three caller.

def by_three(number):
    # ...
    return cube(number)

#5

ohhh I understand now. thank you so much!


#6

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