Trouble with Practice Makes Perfect


#1



https://www.codecademy.com/courses/python-beginner-c7VZg/1/5?curriculum_id=4f89dab3d788890003000096


by_three(3) returned False instead of 27


The program should return the number 27


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


#2

This condition:

number % 3 == 3

is impossible to fulfill.

0 % 3 = 0
1 % 3 = 1
2 % 3 = 2
3 % 3 = 0
4 % 3 = 1
5 % 3 = 2
6 % 3 = 0
7 % 3 = 1
...

Do you see? The only possible values are 0, 1 and 2. So... your function always returns False.


#3

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